Before you can transcode, review, or watermark media files in ApsaraVideo VOD, you must upload them. This topic demonstrates how to upload media files by calling API operations, with a complete Java demo.
Background information
API-based uploads rely on native OSS SDKs. You must retrieve upload URLs and credentials from VOD, Base64-decode them, and call OSS to complete the upload. This topic provides a complete demo to help you avoid issues where media assets get stuck in the Uploading state.
-
API-based upload is an OSS-based upload method. Overview.
-
This topic provides Java sample code. For other languages, check Upload media files using OSS SDKs.
-
Join DingTalk group 11370001915 for technical support.
Before you begin
-
ApsaraVideo VOD is activated. Activate ApsaraVideo VOD.
-
ApsaraVideo VOD is authorized to access OSS via the Cloud Resource Access Authorization page.
-
If you use a RAM user, grant it VOD and OSS management permissions. Create a RAM user and grant permissions. System authorization policies.
Step 1: Install the ApsaraVideo VOD SDK
Step 2: Install the OSS SDK
Step 3: Start upload
This section provides sample code for uploading local files, URL-based network streams, local M3U8 files, multipart upload, and resumable upload. The Sample code section includes the full logic for obtaining and decoding upload URLs and credentials.
Upload files from your local PC
public static void uploadLocalFile(OSSClient ossClient, JSONObject uploadAddress, String localFile) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
try {
File file = new File(localFile);
PutObjectResult result = ossClient.putObject(bucketName, objectName, file);
// If the upload is successful, HTTP status code 200 is returned.
// Configure the parameters of the progress bar during the upload. UploadOss specifies the name of the class that is called to upload local files. Replace UploadOss with the class name that you want to call in actual use.
// PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName,objectName, file).
// <PutObjectRequest>withProgressListener(new UploadOss()));
// System.out.println(result.getResponse().getStatusCode());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
Upload network streams based on URLs
public static void uploadURLFile(OSSClient ossClient, JSONObject uploadAddress, String url) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
try {
InputStream inputStream = new URL(url).openStream();
PutObjectResult result = ossClient.putObject(bucketName, objectName, inputStream);
// If the upload is successful, HTTP status code 200 is returned.
System.out.println(result.getResponse().getStatusCode());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
Upload local M3U8 files
To upload local M3U8 files including part files, specify the M3U8 index file path and all part file paths.
public static void uploadLocalM3U8(OSSClient ossClient, JSONObject uploadAddress, String indexFile, String[] tsFiles ) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
String objectPrefix = uploadAddress.getString("ObjectPrefix");
System.out.println(uploadAddress.toJSONString());
try {
// Upload the index files.
File index = new File(indexFile);
ossClient.putObject(bucketName, objectName, index);
Thread.sleep(200);
// Upload the TS files.
for(String filePath : tsFiles){
File ts = new File(filePath);
ossClient.putObject(bucketName, objectPrefix + ts.getName(), ts);
Thread.sleep(200);
}
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
Perform multipart upload and resumable upload
public static void uploadEnableCheckPointFile(OSSClient ossClient, JSONObject uploadAddress, String localFile) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
try {
UploadFileRequest uploadFileRequest = new UploadFileRequest(bucketName,objectName);
// Configure a parameter using UploadFileRequest.
// Specify the full path of the local file that you want to upload. Example: D:\\localpath\\examplefile.mp4. By default, if you do not specify the full path, the local file is uploaded from the path of the project to which the sample program belongs.
uploadFileRequest.setUploadFile(localFile);
// Specify the number of concurrent threads for the upload task. Default value: 1.
uploadFileRequest.setTaskNum(5);
// Specify the size of each part. Unit: bytes. Valid values: 100 KB to 5 GB. Default value: 100 KB.
uploadFileRequest.setPartSize(1 * 1024 * 1024);
// Specify whether to enable resumable upload. By default, resumable upload is disabled.
uploadFileRequest.setEnableCheckpoint(true);
// Specify the file that records the upload result of each part. This checkpoint file stores information about the upload progress. If a part fails to be uploaded, the task can be continued based on the progress recorded in the checkpoint file. After the local file is uploaded, the checkpoint file is deleted.
// By default, if you do not specify this parameter, the checkpoint file is stored in the same directory as the file that you want to upload. The directory is named ${uploadFile}.ucp.
//uploadFileRequest.setCheckpointFile("yourCheckpointFile");
// Start resumable upload.
ossClient.uploadFile(uploadFileRequest);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
Sample code
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.event.ProgressEvent;
import com.aliyun.oss.event.ProgressEventType;
import com.aliyun.oss.event.ProgressListener;
import com.aliyun.oss.model.*;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.*;
import org.apache.commons.codec.binary.Base64;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
/**
* ***** Important Notes ******!!
* The following Java sample code demonstrates how to upload media asset files to ApsaraVideo VOD through API methods. For detailed OSS information, see https://help.aliyun.com/document_detail/32013.html
* This demo differs from the upload SDK. For information about how to use the upload SDK, see https://help.aliyun.com/document_detail/52200.html
* <p>
* I. Standard audio and video upload
*
* 1. Upload local files using multipart upload with resumable upload support.
* 1.1 When resumable upload is disabled, the maximum supported upload task execution time is 3,000 seconds. The actual uploadable file size depends on your network bandwidth and disk read/write capabilities. See the uploadEnableCheckPointFile function.
* 1.2 When resumable upload is enabled, single files up to 48.8 TB are supported. Note that when resumable upload is enabled, the current upload position is written to a local disk file during upload task execution, which affects your file upload speed. Enable this feature based on your file size.
*
* 2. Upload network streams by specifying a file URL. Single files up to 48.8 TB are supported. See the uploadURLFile function.
*
* 3. Upload file streams by specifying a local file. Resumable upload is not supported. Single files up to 5 GB are supported. See the uploadLocalFile function.
*
* <p>
* II. m3u8 file upload:
* 1. To upload local m3u8 audio and video files (including all fragment files) to VOD, you must upload the local m3u8 manifest file path and all fragment paths. See the uploadLocalM3U8 function.
* 2. We recommend using the URL method for uploading network m3u8 audio and video files.
*
* Note:
* 1) When uploading network m3u8 audio and video files, ensure the URL is accessible. If access permissions are required, configure a signed URL with sufficient validity period to prevent upload failures due to inaccessible URLs.
* <p>
*
* III. Upload progress:
* 1. Default upload progress callback function: You must implement the ProgressListener class. You can skip implementing this class if not needed. See https://help.aliyun.com/document_detail/84796.html;
* 2. Custom upload progress callback function: You can redefine event handling methods based on your business scenario by modifying the upload callback sample function.
* 3. In this demo, see the code example on line 225.
*
* <p>
*
* IV. API descriptions:
* 1. Both CreateUploadVideo and RefreshUploadVideo are interfaces for obtaining credentials. Choose one as needed.
* 2. RefreshUploadVideo can be used to reacquire credentials after timeout or for overwriting file uploads while keeping the same videoId.
* 3. CreateUploadImage can be used to obtain image upload credentials.
* 4. CreateUploadAttachedMedia can be used to obtain auxiliary media asset upload credentials.
* 5. For detailed API descriptions, see https://help.aliyun.com/document_detail/436731.html.
*
* <p>
*
* Note:
* Replace the required parameters in the examples. If you don't need to set optional parameters in the examples, delete them to avoid setting invalid parameter values that don't match your expectations.
*/
public class UploadVodByApiDemo implements ProgressListener {
// Upload progress bar related parameters (optional)
private long bytesWritten = 0;
private long totalBytes = -1;
private boolean succeed = false;
public static void main(String[] argv) {
// Your Alibaba Cloud account AccessKey has permissions to access all APIs. We recommend using a RAM user for API access or routine O&M.
// We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code, as this may lead to AccessKey leakage and compromise the security of all resources under your account.
// This example implements API access authentication by reading the AccessKey from environment variables. Before running the code example, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
// Full path of the local video file to upload to VOD, including the file name extension
String localFile = "E:/demo/demo.mp4";
// Enter the network stream URL. Any accessible URL is acceptable.
String url = "https://bucket-name*****.oss-cn-shanghai.aliyuncs.com/demo/demo.mp4";
try {
// Initialize the VOD client and obtain the upload URL and credentials
DefaultAcsClient vodClient = initVodClient(accessKeyId, accessKeySecret);
// Obtain video upload credentials
CreateUploadVideoResponse createUploadVideoResponse = createUploadVideo(vodClient);
// Obtain refreshed upload credentials
//RefreshUploadVideoResponse refreshUploadVideoResponse = refreshUploadVideo(vodClient);
// Obtain image upload credentials
//CreateUploadImageResponse createUploadImageResponse = createUploadImage(vodClient);
// Obtain auxiliary media asset upload credentials
//CreateUploadAttachedMediaResponse createUploadAttachedMediaResponse = createUploadAttachedMedia(vodClient);
// Upon successful execution, VideoId, UploadAddress, and UploadAuth are returned
String videoId = createUploadVideoResponse.getVideoId();
JSONObject uploadAuth = JSONObject.parseObject(decodeBase64(createUploadVideoResponse.getUploadAuth()));
JSONObject uploadAddress = JSONObject.parseObject(decodeBase64(createUploadVideoResponse.getUploadAddress()));
// Initialize the OSS client using UploadAuth and UploadAddress
// Using this OSSClient object with uploadAuth and uploadAddress completes the video file upload to Alibaba Cloud OSS
OSSClient ossClient = initOssClient(uploadAuth, uploadAddress);
// Upload method - choose as needed
// 1. Local file upload (note: synchronous upload blocks and waits; duration depends on file size and network upstream bandwidth)
uploadLocalFile(ossClient, uploadAddress, localFile);
// 2. Network file upload
//uploadURLFile(ossClient, uploadAddress, url);
// 3. Multipart, resumable upload
//uploadEnableCheckPointFile(ossClient, uploadAddress, localFile);
// 4. Upload m3u8
//String indexFile = "E:/demo/demo.m3u8";
//String[] tsFiles = {"E:/demo/demo_01.ts"};
//uploadLocalM3U8(ossClient, uploadAddress, indexFile, tsFiles);
System.out.println("Put local file succeed, VideoId : " + videoId);
} catch (Exception e) {
System.out.println("Put local file fail, ErrorMessage : " + e.getLocalizedMessage());
}
}
/**
* Initialize the VOD client
* @throws ClientException
*/
public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
// VOD service access region: enter cn-shanghai for the Chinese mainland. For other regions, see https://help.aliyun.com/document_detail/98194.html
String regionId = "cn-shanghai";
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Initialize the OSS client
* @throws ClientException
*/
public static OSSClient initOssClient(JSONObject uploadAuth, JSONObject uploadAddress) {
String endpoint = uploadAddress.getString("Endpoint");
String accessKeyId = uploadAuth.getString("AccessKeyId");
String accessKeySecret = uploadAuth.getString("AccessKeySecret");
String securityToken = uploadAuth.getString("SecurityToken");
return new OSSClient(endpoint, accessKeyId, accessKeySecret, securityToken);
}
/**
* Obtain upload credentials
* @throws ClientException
*/
public static CreateUploadVideoResponse createUploadVideo(DefaultAcsClient vodClient) throws ClientException {
CreateUploadVideoRequest request = new CreateUploadVideoRequest();
request.setFileName("vod_test.m3u8");
request.setTitle("this is title");
//request.setDescription("this is desc");
//request.setTags("tag1,tag2");
//request.setCoverURL("http://vod.****.com/test_cover_url.jpg");
//request.setCateId(-1L);
//request.setTemplateGroupId("34f055******c7af499c73");
//request.setWorkflowId("");
//request.setStorageLocation("");
//request.setAppId("app-1000000");
return vodClient.getAcsResponse(request);
}
/**
* Obtain refreshed credentials
* @throws ClientException
*/
public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient vodClient) throws ClientException {
RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
request.setAcceptFormat(FormatType.JSON);
request.setVideoId("VideoId");
// Set request timeout
request.setSysReadTimeout(1000);
request.setSysConnectTimeout(1000);
return vodClient.getAcsResponse(request);
}
/**
* Obtain image upload credentials
* @throws ClientException
*/
public static CreateUploadImageResponse createUploadImage(DefaultAcsClient vodClient) throws ClientException {
CreateUploadImageRequest request = new CreateUploadImageRequest();
request.setImageType("default");
request.setAcceptFormat(FormatType.JSON);
// Set request timeout
request.setSysReadTimeout(1000);
request.setSysConnectTimeout(1000);
return vodClient.getAcsResponse(request);
}
/**
* Obtain auxiliary media asset upload credentials
* @throws ClientException
*/
public static CreateUploadAttachedMediaResponse createUploadAttachedMedia(DefaultAcsClient vodClient) throws ClientException {
CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
request.setBusinessType("watermark");
request.setMediaExt("png");
request.setAcceptFormat(FormatType.JSON);
// Set request timeout
request.setSysReadTimeout(1000);
request.setSysConnectTimeout(1000);
return vodClient.getAcsResponse(request);
}
/**
* Local file upload
* @throws Exception
*/
public static void uploadLocalFile(OSSClient ossClient, JSONObject uploadAddress, String localFile) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
try {
File file = new File(localFile);
PutObjectResult result = ossClient.putObject(bucketName, objectName, file);
// If the upload succeeds, 200 is returned.
// Specify progress bar parameters while uploading files. UploadOss here is the class name of the calling class. Replace it with the appropriate class name in actual usage.
// PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName,objectName, file).
// <PutObjectRequest>withProgressListener(new UploadOss()));
// System.out.println(result.getResponse().getStatusCode());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
/**
* Network streaming upload
* @throws Exception
*/
public static void uploadURLFile(OSSClient ossClient, JSONObject uploadAddress, String url) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
try {
InputStream inputStream = new URL(url).openStream();
PutObjectResult result = ossClient.putObject(bucketName, objectName, inputStream);
// If the upload succeeds, 200 is returned.
System.out.println(result.getResponse().getStatusCode());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
/**
* Resumable upload
* @throws Exception
*/
public static void uploadEnableCheckPointFile(OSSClient ossClient, JSONObject uploadAddress, String localFile) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
try {
UploadFileRequest uploadFileRequest = new UploadFileRequest(bucketName,objectName);
// Set individual parameters through UploadFileRequest.
// Enter the full path of the local file, for example, D:\\localpath\\examplefile.mp4. If no local path is specified, files are uploaded from the default local path corresponding to the sample program's project.
uploadFileRequest.setUploadFile(localFile);
// Specify the number of concurrent upload threads. Default value: 1.
uploadFileRequest.setTaskNum(5);
// Specify the part size for upload in bytes. Valid values: 100 KB to 5 GB. Default value: 100 KB.
uploadFileRequest.setPartSize(1 * 1024 * 1024);
// Enable resumable upload. Disabled by default.
uploadFileRequest.setEnableCheckpoint(true);
// File that records local multipart upload results. Progress information during upload is saved in this file. If a part upload fails, the next upload resumes from the recorded point. This file is deleted after upload completion.
// If this value is not set, it defaults to the same path as the local file to be uploaded, named ${uploadFile}.ucp.
//uploadFileRequest.setCheckpointFile("yourCheckpointFile");
// Perform resumable upload.
ossClient.uploadFile(uploadFileRequest);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
/**
* Local m3u8 upload
* @throws Exception
*/
public static void uploadLocalM3U8(OSSClient ossClient, JSONObject uploadAddress, String indexFile, String[] tsFiles ) {
String bucketName = uploadAddress.getString("Bucket");
String objectName = uploadAddress.getString("FileName");
String objectPrefix = uploadAddress.getString("ObjectPrefix");
System.out.println(uploadAddress.toJSONString());
try {
// Upload manifest file indexFile
File index = new File(indexFile);
ossClient.putObject(bucketName, objectName, index);
Thread.sleep(200);
// Upload ts files tsFiles
for(String filePath : tsFiles){
File ts = new File(filePath);
ossClient.putObject(bucketName, objectPrefix + ts.getName(), ts);
Thread.sleep(200);
}
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Throwable ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
// Shut down the OSSClient.
if (ossClient != null) {
ossClient.shutdown();
}
}
}
// To use the progress bar, you need to override the callback method. The following is a reference example only.
@Override
public void progressChanged(ProgressEvent progressEvent) {
long bytes = progressEvent.getBytes();
ProgressEventType eventType = progressEvent.getEventType();
switch (eventType) {
case TRANSFER_STARTED_EVENT:
System.out.println("Start to upload......");
break;
case REQUEST_CONTENT_LENGTH_EVENT:
this.totalBytes = bytes;
System.out.println(this.totalBytes + " bytes in total will be uploaded to OSS");
break;
case REQUEST_BYTE_TRANSFER_EVENT:
this.bytesWritten += bytes;
if (this.totalBytes != -1) {
int percent = (int)(this.bytesWritten * 100.0 / this.totalBytes);
System.out.println(bytes + " bytes have been written at this time, upload progress: " + percent + "%(" + this.bytesWritten + "/" + this.totalBytes + ")");
} else {
System.out.println(bytes + " bytes have been written at this time, upload ratio: unknown" + "(" + this.bytesWritten + "/...)");
}
break;
case TRANSFER_COMPLETED_EVENT:
this.succeed = true;
System.out.println("Succeed to upload, " + this.bytesWritten + " bytes have been transferred in total");
break;
case TRANSFER_FAILED_EVENT:
System.out.println("Failed to upload, " + this.bytesWritten + " bytes have been transferred");
break;
default:
break;
}
}
public static String decodeBase64(String s) {
byte[] b = null;
String result = null;
if (s != null) {
Base64 decoder = new Base64();
try {
b = decoder.decode(s);
result = new String(b, "utf-8");
} catch (Exception e) {
}
}
return result;
}
}