Listing Multipart Uploads (SDK for Java)
Function
This API lists ongoing multipart uploads.
Ongoing multipart uploads are the multipart uploads that have been initiated but have not been completed or aborted. A maximum of 1,000 multipart uploads can be returned in a response. If there are over 1,000 ongoing tasks satisfying the list criteria, you need to send more requests to query additional multipart uploads.
![](https://support.huaweicloud.com/intl/en-us/sdk-java-devg-obs/public_sys-resources/notice_3.0-en-us.png)
If you have any questions during development, post them on the Issues page of GitHub.
Restrictions
- To list multipart uploads, you must be the bucket owner or have the required permission (obs:bucket:ListBucketMultipartUploads in IAM or ListBucketMultipartUploads in a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
- By default, only the bucket owner and multipart upload initiator have this permission. The bucket owner can grant others the ListBucketMultipartUploads permission.
Method
obsClient.listMultipartUploads(ListMultipartUploadsRequest request)
Request Parameters
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
request |
Yes |
Explanation: Request parameters for listing multipart uploads. For details, see Table 2. |
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
bucketName |
String |
Yes |
Explanation: Bucket name. Restrictions:
Default value: None |
prefix |
String |
No |
Explanation: Prefix that the object names in the multipart uploads to be listed must contain. Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, the multipart uploads of logs/day1, logs/day2, and logs/day3 will be returned. If you leave this parameter blank, all multipart uploads in the bucket will be returned. Restrictions: The value must contain 1 to 1,024 characters. Default value: None |
delimiter |
String |
No |
Explanation: Object names are grouped by this parameter, which is often used with prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one commonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one commonPrefixes. Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix, and bbcde is grouped separately into another commonPrefixes with bbcd as the prefix. Value range: The value must contain 1 to 1,024 characters. Default value: None |
maxUploads |
Integer |
No |
Explanation: Maximum number of multipart uploads to list. Restrictions: If the specified value is greater than 1000, only 1,000 multipart uploads are returned. Value range: An integer from 1 to 1000 Default value: 1000 |
keyMarker |
String |
No |
Explanation: Object name after which the multipart upload listing begins. Value range: The value of nextKeyMarker in the response body of the last request. Default value: None |
uploadIdMarker |
String |
No |
Explanation: Upload ID after which the multipart upload listing begins. Restrictions: This parameter must be used together with keyMarker, indicating multipart uploads with IDs greater than the specified uploadIdMarker for the specified keyMarker are listed. Value range: The value of nextUploadIdMarker in the response body of the last request. Default value: None |
encodingType |
String |
No |
Explanation: Encoding type for some elements in the response. If delimiter, keyMarker, prefix, nextKeyMarker, and objectKey contain control characters that are not supported by the XML 1.0 standard, you can set encodingType to encode delimiter, keyMarker, prefix (including the prefix in commonPrefixes), nextKeyMarker, and objectKey in the response. Value range: url Default value: None. If you leave this parameter blank, encoding is not applied. |
Responses
Parameter |
Type |
Description |
---|---|---|
statusCode |
int |
Explanation: HTTP status code. Value range: A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code. Default value: None |
responseHeaders |
Map<String, Object> |
Explanation: HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. Default value: None |
bucket |
String |
Explanation: Bucket name. Restrictions:
Default value: None |
keyMarker |
String |
Explanation: Object name after which the multipart upload listing begins, which is consistent with that set in the request. Value range: The value must contain 1 to 1,024 characters. Default value: None |
uploadIdMarker |
String |
Explanation: Upload ID after which the multipart upload listing begins, which is consistent with that set in the request. Value range: The value must contain 1 to 32 characters. Default value: None |
nextKeyMarker |
String |
Explanation: Object name to start with for the next multipart upload listing request. If only part of multipart uploads are returned for the current request, this parameter is included in the response for setting keyMarker in the subsequent request. Value range: The value must contain 1 to 1,024 characters. Default value: None |
nextUploadIdMarker |
String |
Explanation: Upload ID to start with for the next multipart upload listing request. It is used with the nextKeyMarker parameter. If only part of multipart uploads are returned for the current request, this parameter is included in the response for setting uploadIdMarker in the subsequent request. Value range: The value must contain 1 to 32 characters. Default value: None |
prefix |
String |
Explanation: Object name prefix in multipart uploads, which is consistent with that set in the request. Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, the multipart uploads of logs/day1, logs/day2, and logs/day3 will be returned. If you leave this parameter blank, all multipart uploads in the bucket will be returned. Restrictions: The value must contain 1 to 1,024 characters. Default value: None |
maxUploads |
int |
Explanation: Maximum number of listed multipart uploads, which is consistent with that set in the request. Restrictions: If the specified value is greater than 1000, only 1,000 multipart uploads are returned. Value range: An integer from 1 to 1000 Default value: 1000 |
truncated |
boolean |
Explanation: Whether all multipart uploads are returned in the response. Value range:
Default value: None |
multipartTaskList |
List<MultipartUpload> |
Explanation: List of multipart uploads. For details, see Table 4. |
delimiter |
String |
Explanation: A character used to group object names in multipart uploads, which is consistent with that set in the request. This parameter is often used with prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one commonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one commonPrefixes. Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix, and bbcde is grouped separately into another commonPrefixes with bbcd as the prefix. Value range: The value must contain 1 to 1,024 characters. Default value: None |
commonPrefixes |
String[] |
Explanation: List of object name prefixes grouped according to the delimiter parameter (if specified). Value range: The value must contain 1 to 1,024 characters. Default value: None |
Parameter |
Type |
Description |
---|---|---|
bucketName |
String |
Explanation: Bucket name. Restrictions:
Default value: None |
objectKey |
String |
Explanation: Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. For example, if the address for accessing the object is examplebucket.obs.ap-southeast-1.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt. Value range: The value must contain 1 to 1,024 characters. Default value: None |
uploadId |
String |
Explanation: Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. Value range: The value must contain 1 to 32 characters. Default value: None |
initiatedDate |
java.util.Date |
Explanation: Time when the multipart upload is initiated. Restrictions: The time must be in the ISO8601 format. Default value: None |
storageClass |
Explanation: Storage class of the object to be uploaded. Value range: See Table 5. Default value: None |
|
initiator |
Explanation: Initiator of the multipart upload. For details, see Table 6. |
|
owner |
Explanation: Owner of the multipart upload, which is consistent with initiator. For details, see Table 6. |
Constant |
Default Value |
Description |
---|---|---|
STANDARD |
STANDARD |
Standard storage class |
WARM |
WARM |
Infrequent Access storage class. |
COLD |
COLD |
Archive storage class. |
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
id |
String |
Yes |
Explanation: Account (domain) ID of the bucket owner. Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? Default value: None |
displayName |
String |
No |
Explanation: Account name of the owner. Value range: To obtain the account name, see How Do I Get My Account ID and User ID? Default value: None |
Code Example: Listing Multipart Uploads
This example lists up to 1,000 multipart uploads of bucket examplebucket.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.ListMultipartUploadsRequest; import com.obs.services.model.MultipartUpload; import com.obs.services.model.MultipartUploadListing; public class ListMultipartUploads001 { public static void main(String[] args) { // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. // Obtain an AK/SK pair on the management console. String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. String securityToken = System.getenv("SECURITY_TOKEN"); // Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one in your actual situation. String endPoint = "https://obs.ap-southeast-1.myhuaweicloud.com"; // Obtain an endpoint using environment variables or import it in other ways. //String endPoint = System.getenv("ENDPOINT"); // Create an ObsClient instance. // Use the permanent AK/SK pair to initialize the client. ObsClient obsClient = new ObsClient(ak, sk,endPoint); // Use the temporary AK/SK pair and security token to initialize the client. // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { ListMultipartUploadsRequest request = new ListMultipartUploadsRequest("examplebucket"); MultipartUploadListing result = obsClient.listMultipartUploads(request); for (MultipartUpload upload : result.getMultipartTaskList()) { System.out.println("UploadId:" + upload.getUploadId()); System.out.println("ObjectKey:" + upload.getObjectKey()); System.out.println("InitiatedDate:" + upload.getInitiatedDate()); } System.out.println("ListMultipartUploads successfully"); } catch (ObsException e) { System.out.println("ListMultipartUploads failed"); // Request failed. Print the HTTP status code. System.out.println("HTTP Code:" + e.getResponseCode()); // Request failed. Print the server-side error code. System.out.println("Error Code:" + e.getErrorCode()); // Request failed. Print the error details. System.out.println("Error Message:" + e.getErrorMessage()); // Request failed. Print the request ID. System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("ListMultipartUploads failed"); // Print other error information. e.printStackTrace(); } } } |
Code Example: Listing Multipart Uploads Using Pagination
This example lists over 1,000 multipart uploads using pagination.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.ListMultipartUploadsRequest; import com.obs.services.model.MultipartUpload; import com.obs.services.model.MultipartUploadListing; public class ListMultipartUploads002 { public static void main(String[] args) { // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. // Obtain an AK/SK pair on the management console. String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. String securityToken = System.getenv("SECURITY_TOKEN"); // Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one in your actual situation. String endPoint = "https://obs.ap-southeast-1.myhuaweicloud.com"; // Obtain an endpoint using environment variables or import it in other ways. //String endPoint = System.getenv("ENDPOINT"); // Create an ObsClient instance. // Use the permanent AK/SK pair to initialize the client. ObsClient obsClient = new ObsClient(ak, sk,endPoint); // Use the temporary AK/SK pair and security token to initialize the client. // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { ListMultipartUploadsRequest request = new ListMultipartUploadsRequest("examplebucket"); MultipartUploadListing result; do { result = obsClient.listMultipartUploads(request); for (MultipartUpload upload : result.getMultipartTaskList()) { System.out.println("UploadId:" + upload.getUploadId()); System.out.println("ObjectKey:" + upload.getObjectKey()); System.out.println("InitiatedDate:" + upload.getInitiatedDate()); } request.setKeyMarker(result.getNextKeyMarker()); request.setUploadIdMarker(result.getNextUploadIdMarker()); } while (result.isTruncated()); System.out.println("ListMultipartUploads successfully"); } catch (ObsException e) { System.out.println("ListMultipartUploads failed"); // Request failed. Print the HTTP status code. System.out.println("HTTP Code:" + e.getResponseCode()); // Request failed. Print the server-side error code. System.out.println("Error Code:" + e.getErrorCode()); // Request failed. Print the error details. System.out.println("Error Message:" + e.getErrorMessage()); // Request failed. Print the request ID. System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("ListMultipartUploads failed"); // Print other error information. e.printStackTrace(); } } } |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot