The upload SDK provides the file list management and upload control functions. File list management allows you to add, delete, cancel, resume, retrieve, and clear files. Upload control allows you to start, stop, pause, and resume file upload. The SDK provides callback events to monitor the status and progress changes during upload.
Initialize the upload SDK > Select a file > Add the file to the list > Start upload > Upload completion events
Initialize the upload SDK
The AccessKey and token can be used to grant permissions during initialization. Considering the security of the AccessKey stored on the client, it is recommended that the AccessKey be used only for testing and the token be used in the production environment. For details, see Developer guide > Upload a video file > Overview.
Select a file
Select a local file to be uploaded.
Add the file to the list
Add all files to be uploaded to the list using addFile.
Call start to start the upload process.
Upload completion events
The events include OnUploadSucceed and OnUploadFailed.
Multipart upload and status
The SDK uses the multipart upload mode, in which the status is valid only for one execution. If the app exits due to a specific reason (for example, shutdown, closing the browser page, closing the app, or abnormal app exit), the file must be uploaded again.
The token is only valid for a certain period. After the token expires, the upload process is interrupted and cannot be automatically resumed. To resume upload, obtain a new token from the backend and call the resumeUploadWithAuth function.
Switching between a 3G/4G network and a Wi-Fi network on the mobile end
To avoid traffic waste on 3G/4G networks, when the app switches to a 3G/4G network, it must automatically detect the network and call pause to suspend upload. After the app detects that a Wi-Fi network is used, it calls resume to resume upload.
The SDKs of the following three types of terminals are provided:
|addFile||Adds a file to the list. Files are uploaded in order of addition.|
|deleteFile||Deletes a file from the list.|
|listFiles||Obtains the list.|
|resumeUploadWithToken||Uses a new token to resume upload after the existing token expires.|
|OnUploadStarted||This event is triggered when upload of each file starts.|
|OnUploadFailed||Upload fails. If resumable errors occur, for example the network has an exception or times out, the file upload can be resumed. If non-resumable errors occur, for example the upload credential is incorrect or the file does not exist, the file upload fails.|
|OnUploadProgress||The upload progress report. This event is triggered when multipart upload succeeds.|
|OnUploadTokenExpired||The token times out. To resume upload, obtain a new token from the server and call the resumeUploadWithToken function.|