Help Center> Object Storage Service> Java> FAQs (SDK for Java)> How Can I Perform a Multipart Upload? (Java SDK)
Updated on 2024-01-16 GMT+08:00

How Can I Perform a Multipart Upload? (Java SDK)

In a multipart upload, you can specify a part of the file to be uploaded by performing the following steps:

  1. You need to initialize an instance of ObsClient by using AK, SK, and endpoint.
  2. Specify the bucket name and object name to initialize InitiateMultipartUploadRequest. Call InitiateMultipartUploadRequest.setMetadata to set the metadata of the object to be uploaded. Then, call ObsClient.initiateMultipartUpload to initialize a multipart upload task. A globally unique identifier (upload ID) is returned to identify this task.
  3. Specify the bucket name and object name to initialize UploadPartRequest. Call UploadPartRequest.setUploadId to set the upload ID to which the part to be uploaded belongs; call setPartNumber to set the part number of the part; call setFile to set the large file to which the part belongs; call setPartSize to set the part size; and then call ObsClient.uploadPart to upload the part. The ETag value of the uploaded part is returned.
  4. After all parts are uploaded, specify the bucket name, object name, uploadId, and partEtags to initialize a CompleteMultipartUploadRequest request. Then, call ObsClient.completeMultipartUpload to merge parts.

For details, see Multipart Upload (SDK for Java).