Last update:2023-02-02 14:07:44
Cloud VoD provides Android upload SDK for you to embed in your APP, making it easier upload files from Android mobile devices to Cloud VoD.
Download SDK
Source Code and Install Guide
Visit Get Video Upload Token for more details.
Initialize to set the upload domain, timeout, upload concurrency and retries.
com.chinanetcenter.wcs.android.Config.java
public static final String PUT_URL = "upload.cloudv.haplat.net";
FileUploader.setUploadUrl("upload.cloudv.haplat.net");
ClientConfig config = new ClientConfig();
// Set multi-part upload concurrency at 10,default at 5.
config.setMaxConcurrentRequest(10);
FileUploader.setClientConfig(config);
import com.chinanetcenter.wcs.android.api.ParamsConf;
conf = new ParamsConf();
conf.fileName = '<Name of the file to be uploaded>';
conf.keyName = <File name to be displayed on console>;
conf.mimeType = '<mimeType>';
FileUploader.setParams(conf);
The default block size is 4M, must be a multiple of 4M, and cannot exceed 100M maximum. The default chunk size is 4M, must be a multiple of 64K, and cannot exceed the block size maximum.
FileUploader.setBlockConfigs(8, 512); //Set the block size at 8MB and the chunk size at 512KB
/**
* Example
*/
private void uploadFile(File srcFile) {
/**
* UPLOADER_TOKEN--upload token, which can be retrieved from Get Upload Token API.
* srcFile-content to be uploaded
*/
FileUploader.upload(UPLOADER_TOKEN, srcFile, new FileUploaderListener() {
/** Callback for upload success **/
@Override
public void onSuccess(int status, JSONObject responseJson) {
Log.d(TAG, "responseJson : " + responseJson.toString());
}
/** Callback for upload fail **/
@Override
public void onFailure(OperationMessage operationMessage) {
Log.e(TAG, "errorMessage : " + operationMessage.toString());
}
/** Callback for upload progress **/
@Override
public void onProgress(int bytesWritten, int totalSize) {
Log.d(TAG, String.format("Progress %d from %d (%s)", bytesWritten, totalSize, (totalSize > 0) ? ((float) bytesWritten / totalSize) * 100 : -1));
}
});
}
It will take a long time to upload large files on mobile devices, and once the file upload is terminated due to any abnormality, all content need to be re-uploaded, which affects user experience. Thus, we recommend you to use Multi-part Upload when uploading large files.
Multi-part Upload is to cut a large file into multiple blocks and chunks of custom size, and then upload these blocks in parallel. If a block fails to upload, the client only needs to re-upload this block.
private static final long DEFAULT_BLOCK_SIZE = 1 * 1024 * 1024;
/**
* context--relevant information
* uploadToken--upload token
* ipaFile--content to be uploaded
* DEFAULT_BLOCK_SIZE--block size
*/
FileUploader.sliceUpload(context, uploadToken, ipaFile, DEFAULT_BLOCK_SIZE, new SliceUploaderListener() {
/** Callback for upload success **/
@Override
public void onSliceUploadSucceed(JSONObject jsonObject) {
Log.d("CNCLog", "slice upload succeeded.");
}
/** Callback for upload fail **/
@Override
public void onSliceUploadFailured(OperationMessage operationMessage) {
Log.d("CNCLog", "slice upload failured.");
}
/** Callback for upload progress **/
@Override
public void onProgress(long uploaded, long total) {
Log.d("CNCLog", String.format(Locale.CHINA, "uploaded : %s, total : %s", uploaded, total));
}
});