Documentation
SuperBoard_backup Super Board (Full version)
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • Super Board (Full version)
  • Guides
  • Manage shared files

Manage shared files

Last updated:2022-12-21 17:44

This document describes how to manage shared files.

Upload files

Call the file upload method in ZegoSuperBoardManager to upload a file to the ZEGOCLOUD file cloud server. After the file is successfully uploaded, fileID of the file is obtained. You can call the createFileView method in ZegoSuperBoardManager and transfer ZegoCreateFileConfig to load the file.

The file upload process is divided into two phases: ZegoSuperBoardUploadFileState.Upload (file upload) and ZegoSuperBoardUploadFileState.Convert (format conversion).

  • Upload phase: If the upload is normal, multiple callbacks are generated, and each callback includes the file upload progress. For example, if the current upload progress is 50%, the content of infoMap is {"upload_percent":0.50}. If the current upload progress is 100%, the content of infoMap is {"upload_percent":1.00}.
  • Format conversion phase: If the conversion is successful, only one callback is generated, including the file ID after the conversion. For example, if the conversion is completed, the content of infoMap is {"upload_fileid":"ekxxxxxxxxv"}.

The files to be uploaded must satisfy the following specifications:

  1. Use Microsoft Office 2013 or later to edit or save files. Files saved using lower versions of Microsoft Office or other office software, such as WPS, Keynote, and Microsoft Office 2003, are not supported.

  2. The files must be editable and cannot be read-only, encrypted, or under protection; otherwise, transcoding fails.

For all specifications, refer to File specifications.

Upload common files

Call the uploadFile method to upload common files.

// filePath: Absolute path of the to-be-uploaded file, which can be obtained using the API of the iOS system.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];

// Type of rendering mode after the file is uploaded and transcoded is ZegoDocsViewRenderTypeVector by default. If the business of iOS, Web, Windows, Mac, or mini program is involved, you are advised to use the ZegoDocsViewRenderTypeVectorAndIMG mode.
ZegoSuperBoardRenderType renderType = ZegoSuperBoardRenderTypeVectorAndIMG;

[[ZegoSuperBoardManager sharedInstance] uploadFile:filePath renderType:renderType completionBlock:^(ZegoSuperBoardUploadFileState state, ZegoSuperBoardError errorCode, NSDictionary * _Nonnull infoDictionary) {

    if (errorCode == ZegoSuperBoardSuccess) {
        if (state == ZegoSuperBoardUploadFileStateUpload) {
            // Uploading...
            NSNumber * upload_percent = infoDictionary[SUPER_BOARD_UPLOAD_PERCENT];

            if (upload_percent.integerValue == 1){
                /** Transcoding...*/
            }
        } else if (state == ZegoSuperBoardUploadFileStateConvert){
            /** Converted. */
            NSString *fileID = infoDictionary[SUPER_BOARD_UPLOAD_FILEID];

        }
    } else {
        /** Upload failed. */
    }

}];

You can also use the Server API Request file transcoding to perform file transcoding and obtain the fileID.

Upload H5 files

You can use ZegoUploadCustomH5Config to set the parameters for uploading H5 files and call the uploadH5File method to upload H5 files.

// filePath: Absolute path of the to-be-uploaded file, which can be obtained using the API of the iOS system.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"zip"];

ZegoUploadCustomH5Config * config = [ZegoUploadCustomH5Config new];
config.pageCount = 2; // Page count.
config.width = 960;  // Page width.
config.height = 540; // Page height.
config.thumbnailList = nil; // If a thumbnail is required, transfer the thumbnail website array, for example, @[@"http://url1.jpg",@"http://url2.jpg"].

[[ZegoSuperBoardManager sharedInstance] uploadH5File:filePath config:config completionBlock:^(ZegoSuperBoardUploadFileState state, ZegoSuperBoardError errorCode, NSDictionary * _Nonnull infoDictionary) {

    if (errorCode == ZegoSuperBoardSuccess) {
        if (state == ZegoSuperBoardUploadFileStateUpload) {
            // Uploading...
            NSNumber * upload_percent = infoDictionary[SUPER_BOARD_UPLOAD_PERCENT];

            if (upload_percent.integerValue == 1){
                /** Transcoding...*/
            }
        } else if (state == ZegoSuperBoardUploadFileStateConvert){
            /** Converted. */
            NSString *fileID = infoDictionary[SUPER_BOARD_UPLOAD_FILEID];

        }
    } else {
        /** Upload failed. */
    }
}];

Cache files

Cache files

Call the cacheFileWithFileID method to upload common files.

// Define the SEQ for recording cache first, which will be used when the cache is canceled.
@property (nonatomic,assign) unsigned int cacheSeq;

// Cache the specified file.
NSString * fileID = @"";// File ID obtained after file upload.
self.cacheSeq = [[ZegoSuperBoardManager sharedInstance] cacheFileWithFileID:fileID completionBlock:^(ZegoSuperBoardCacheState state, ZegoSuperBoardError errorCode, NSDictionary * _Nonnull infoDictionary) {
    if (errorCode == ZegoSuperBoardSuccess) {
        if (state == ZegoSuperBoardCacheStateCaching) {
            NSNumber * download_percent = infoDictionary[SUPER_BOARD_CACHE_PERCENT];
            // Caching...
        } else if (state == ZegoSuperBoardCacheStateCached){
            // Cached.
        }
    } else {
        // Cache failed.
    }
}];

Cancel file caching

Call the [cancelCacheFile|_blank]/article/api?doc=superboard_APIobjective-c_iosclass~ZegoSuperBoardManager%2BFile#cancel-cache-file-with-seq-seq-completion-block) method to upload common files.

// Save the SEQ value self.cacheSeq returned by calling the cacheFileWithFileID API,
// which is used in the parameter for canceling the cache.
[[ZegoSuperBoardManager sharedInstance] cancelCacheFileWithSeq:self.cacheSeq completionBlock:^(ZegoSuperBoardError errorCode) {
    NSString *msg;
    if (errorCode == ZegoSuperBoardSuccess) {
        // Canceled.
    } else {
        // Canceling failed.
    }        
}];

Check whether a file has been cached

Call the queryFileCachedWithFileID method to check whether a file has been cached.

// Use fileID to check whether the specified file has been cached.
[[ZegoSuperBoardManager sharedInstance] queryFileCachedWithFileID:fileID completionBlock:^(ZegoSuperBoardError errorCode, BOOL fileCached) {
    if (errorCode == ZegoSuperBoardSuccess) {
        // Query succeeded.
        // If fileCached is YES, the file has been cached.
        // If fileCached is NO, the file has not been cached.
    }else{
        // Query failed.
    }
}];
Page Directory
  • Free trial
  • 提交工单
    咨询集成、功能及报价等问题
    电话咨询
    400 1006 604
    Get Consulting
    Scan Wechat QR code