Super Board
  • iOS
  • Android : Java
  • Web
  • Introduction
    • Overview
    • Restrictions
  • Sample code
  • Demo app
  • SDK downloads
  • Getting started
  • Guides
    • Draw
    • Turn pages
    • Zoom in or out
    • Switch a whiteboard
    • Get whiteboard list
    • Manage shared files
    • Create and use H5 file
  • Tutorials
    • Create and switch between multiple wihteboards
  • Error codes
  • Server API V2
  • API Documents
  • FAQ

Manage shared files

Last updated:2022-03-28 14:59

This document describes how to manage shared files.

Upload files

Call the file upload method in ZegoSuperBoardManager to upload a file to the ZEGO 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.
  3. If you are using the Super Board SDK 2.0, files may fail to upload due to the storage issue of the Android partition. Upgrade the SDK to the latest version or refer to How to deal with a file upload failure?\ for setting.

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.
String filePath = "";
ZegoSuperBoardRenderType renderType = ZegoSuperBoardRenderType.IMG;// For example, convert a file to an image format.
ZegoSuperBoardManager.getInstance().uploadFile(filePath, renderType, new IZegoSuperBoardUploadFileListener() {
    @Override
    public void onUpload(ZegoSuperBoardUploadFileState state, int errorCode, @NonNull HashMap<String, Object> infoMap) {
        if (errorCode == ZegoSuperBoardError.ZegoSuperBoardSuccess) {
            if (state == ZegoSuperBoardUploadFileState.Upload) {
                // Uploading...
                float uploadPercent = (float) infoMap.get("upload_percent");
                if (uploadPercent == 1f){
                /** Transcoding...*/
                }
            } else if (state == ZegoSuperBoardUploadFileState.Convert){
                /** Converted. */
                String fileID = (String) infoMap.get(ZegoSuperBoardError.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 uploadH5File method to upload H5 files.


String filePath = "";

ZegoUploadCustomH5Config mH5Config = new ZegoUploadCustomH5Config();
mH5Config.height = 960;
mH5Config.width = 540;
mH5Config.pageCount = 5;

ZegoSuperBoardManager.getInstance().uploadH5File(filePath, mH5Config, new IZegoSuperBoardUploadFileListener() {
    @Override
    public void onUpload(ZegoSuperBoardUploadFileState state, int errorCode, @NonNull HashMap<String, Object> infoMap) {
        if (errorCode == ZegoSuperBoardError.ZegoSuperBoardSuccess) {
            if (state == ZegoSuperBoardUploadFileState.Upload) {
                // Uploading...
                float uploadPercent = (float) infoMap.get("upload_percent");
                if (uploadPercent == 1f){
                    /** Transcoding...*/
                }
            } else if (state == ZegoSuperBoardUploadFileState.Convert){
                /** Converted. */
                String fileID = (String) infoMap.get(ZegoSuperBoardError.UPLOAD_FILEID);
            }
        } else {
            /** Upload failed. */
        }
    }
});

Cache files

Cache files

Call the cacheFile method to upload common files.

int seq = ZegoSuperBoardManager.getInstance().cacheFile(fileID, new IZegoSuperBoardCacheFileListener() {
    @Override
    public void onCache(ZegoSuperBoardCacheFileState state, int errorCode, @NonNull HashMap<String, Object> infoMap) {
        if (errorCode == ZegoSuperBoardError.ZegoSuperBoardSuccess) {
            if (state == ZegoSuperBoardCacheFileState.Caching) {
                float cachePercent = (float) infoMap.get("cache_percent") * (float) 100;
                // Caching...
            } else if (state == ZegoSuperBoardCacheFileState.Cached) {
            // Cached.
            }
        } else {
        // Cache failed.
        }
    }
});

Cancel file caching

Call the cancelCacheFile method to upload common files.

// Save the SEQ value returned by calling the cacheFile() API,
// which is used in the parameter for canceling the cache.
ZegoSuperBoardManager.getInstance().cancelCacheFile(seq, new IZegoSuperBoardApiCalledCallback() {
    @Override
    public void onApiCalledResult(int errorCode) {
        // If errorCode is 0, the cache is successfully cached.
    }
});

Check whether a file has been cached

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

// Use fileID to check whether the specified file has been cached.
ZegoSuperBoardManager.getInstance().queryFileCached(fileID, new IZegoSuperBoardQueryFileCachedListener() {
    @Override
    public void onQueryCached(int errorCode, boolean fileCached) {
        // Use fileCached to check whether a file has been cached.
    }
});