logo
On this page

How to handle file upload or loading failure?

2021-11-18
Products / Plugins:File sharing
Platform / Framework:iOS / Android

Problem Description

  1. Call the file sharing SDK upload file interface to upload the target file, and receive an error code and message indicating transcoding failure.
  2. Call the file sharing SDK load file interface and encounter loading failure (error code ZegoDocsViewErrorServerFileNotExist, 2030010).
  3. Call the file sharing SDK load file interface and encounter loading failure (error code ZegoDocsViewErrorSizeInvalid, 2030004).

Problem Cause

Reasons for file transcoding failure

File transcoding failure may be caused by the following reasons:

  • The source file is not editable. The source file to be transcoded must be editable. Transcoding is not supported for files that are "read-only", "binary encrypted", or have other protections that prevent content from being edited.
  • The image structure contained in the user's file is corrupted. During the process of compressing images in the file, the images are damaged and the structure is corrupted. At this time, although the images can be previewed normally on the local computer, they will fail when uploading files using the file sharing SDK.

Reasons for loading file failure (error code 2030010)

The error code 2030010 returned when loading a file indicates that the file on the server cannot be found. The possible reasons are:

  • The fileID passed in is incorrect, and the corresponding file cannot be found.
  • The corresponding file has been deleted.
  • Different AppIDs were used when uploading and loading files, so the file cannot be accessed.

Reasons for loading file failure (error code 2030004)

The error code 2030004 returned when loading a file indicates that the valid width and height of the current ZegoDocsView cannot be obtained. The reasons are as follows:

When the file sharing SDK loads ZegoDocsView, it needs to read the valid width and height of the View to perform file image slicing. If the SDK cannot get the valid width and height when loading, it will report an error and throw this error code.

Solution

Solution for file transcoding failure

  • The file sharing SDK does not support files saved by WPS. Please ensure that your file is generated by Microsoft Office.

  • Please ensure that your file is editable: it does not have "read-only" attributes; it has not been encrypted; the image content contained in the file is not corrupted and can be displayed normally on the computer.

  • If your file type is an image and it imports normally in Microsoft Office PPT but cannot be converted to PDF, you can determine the failure reason and handle it through the following steps:

    1. Use an image processing tool to determine if the image is corrupted: for example, if using the PS tool to import the image results in an error "IDAT: incorrect data check", it means the image is corrupted;
    2. Use Microsoft Office PPT to "Save As" the image. PPT will reprocess the image. At this time, re-insert the saved image into the source file, and the file transcoding can proceed normally.

Solution for loading file failure (error code 2030010)

  • Confirm whether the fileID passed in is correct. The fileID obtained after the file is successfully uploaded and the fileID at the time of loading must be consistent.
  • Confirm whether you have actively deleted the uploaded file to the cloud by calling the server API Delete File.
  • Confirm whether the AppID used when uploading the file is consistent with the AppID used when loading the file. If they are inconsistent, the corresponding file cannot be accessed.

Solution for loading file failure (error code 2030004)

Solution 1:

  • Android Because when ZegoDocsView gets the width and height, the drawing of the View is not yet complete, there is a timing issue. So in Android, a common approach is to use Handler as the basis and call View.post() to adjust the execution timing of the passed task to after the View drawing is complete, thus ensuring that the valid width and height of the View can be obtained.

    The specific detailed usage method can be referenced in the sample demo. The sample code is shown as follows:

        ZegoDocsView zegoDocsView = new ZegoDocsView(this);
        zegoDocsView.post(new Runnable() {
            @Override
            public void run() {
                zegoDocsView.loadFile("xxxxxx", "", new IZegoDocsViewLoadListener() {
                    @Override
                    public void onLoadFile(int errorCode) {
                        if (errorCode == 0) {
                            // File loaded successfully
                        } else {
                            // File loading failed
                        }
                    }
                });
            }
        });
  • iOS Set the width and height during initialization to solve the problem.

    ZegoDocsView * docsView = [[ZegoDocsView alloc] init];
    // Set a non-zero width and height
    [docsView setFrame:CGRectMake(0, 0, 1280, 720)];
    [docsView loadFileWithFileID:@"xxx" authKey:@"" completionBlock:^(ZegoDocsViewError errorCode) {
        if (errorCode == 0) {
                // File loaded successfully
        } else {
                // File loading failed
        }
    }];

Solution 2:

When the interface is just initialized, the valid width and height cannot be obtained. ZegoDocsView provides an interface setEstimatedSize to pass in an estimated value of the current view, thus ensuring that loadFile can succeed.

  • Android Sample code

    ZegoDocsView zegoDocsView = new ZegoDocsView(this);
    zegoDocsView.setEstimatedSize(1280, 720);
    zegoDocsView.loadFile("xxx", "", new IZegoDocsViewLoadListener() {
        @Override
        public void onLoadFile(int errorCode) {
            if (errorCode == 0) {
                // File loaded successfully
            } else {
                // File loading failed
            }
        }
    });
  • iOS Sample code

    ZegoDocsView * docsView = [[ZegoDocsView alloc] init];
    // When unsure about the view's width and height, you can set an estimated value
    [docsView setEstimatedSize:CGSizeMake(1280, 720)];
    [docsView loadFileWithFileID:@"xxx" authKey:@"" completionBlock:^(ZegoDocsViewError errorCode) {
        if (errorCode == 0) {
                // File loaded successfully
        } else {
                // File loading failed
        }
    }];

Previous

After cloud recording ends, I don't see the recorded files in cloud storage. How to handle this?

Next

How to obtain and upload audio Dump files?