This document describes how to manage shared 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).
infoMap
is {"upload_percent":0.50}
. If the current upload progress is 100%, the content of infoMap
is {"upload_percent":1.00}
.infoMap
is {"upload_fileid":"ekxxxxxxxxv"}
.The files to be uploaded must satisfy the following specifications:
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.
The files must be editable and cannot be read-only, encrypted, or under protection; otherwise, transcoding fails.
For all specifications, refer to File specifications.
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.
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. */
}
}];
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.
}
}];
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.
}
}];
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.
}
}];