Listing Multipart Uploads (SDK for Node.js)
If you have any questions during development, post them on the Issues page of GitHub.
Function
This API lists multipart uploads that have been initiated but not completed or cancelled.
You can list all the multipart uploads that are not assembled or aborted in a bucket. Each request can return up to 1,000 multipart uploads. If a bucket contains more than 1,000 multipart uploads, InterfaceResult.IsTruncated in the response is true, indicating not all uploads were listed. In such case, you can use InterfaceResult.NextKeyMarker and InterfaceResult.NextUploadIdMarker to obtain the start position for the next listing.
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.
- To learn about the mappings between OBS regions and endpoints, see Regions and Endpoints.
Method
ObsClient.listMultipartUploads(params)
Request Parameters
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
Bucket |
string |
Yes |
Explanation: Bucket name Restrictions:
Value range: The value can contain 3 to 63 characters. 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 that contain logs/day1, logs/day2, or logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all multipart uploads in the bucket will be returned. Restrictions: The value can contain 1 to 1,024 characters. Value range: None Default value: None |
MaxUploads |
number |
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 |
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 placed separately into another CommonPrefixes with bbcd as the prefix. Restrictions: None Value range: The value can contain 1 to 1,024 characters. Default value: None |
KeyMarker |
string |
No |
Explanation: Object name to start with when listing multipart uploads Restrictions: None Value range: The value of NextKeyMarker in the response body of the last request. Default value: None |
UploadIdMarker |
string |
No |
Explanation: Upload ID to start with when listing multipart uploads Restrictions: This parameter is valid only when used with KeyMarker. If both parameters are specified, 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 Key in the response. If Key in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode Key. Restrictions: None Value range: url Default value: None. If you leave this parameter blank, encoding is not applied. |
Responses
Type |
Description |
---|---|
NOTE:
This API returns a Promise response, which requires the Promise or async/await syntax. |
Explanation: Returned results. For details, see Table 3. |
Parameter |
Type |
Description |
---|---|---|
CommonMsg |
Explanation: Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. |
|
InterfaceResult |
Explanation: Results outputted for a successful call. For details, see Table 5. Restrictions: This parameter is not included if the value of Status is greater than 300. |
Parameter |
Type |
Description |
Status |
number |
Explanation: HTTP status code returned by the OBS server. Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For details, see Status Codes. |
Code |
string |
Explanation: Error code returned by the OBS server. |
Message |
string |
Explanation: Error description returned by the OBS server. |
HostId |
string |
Explanation: Request server ID returned by the OBS server. |
RequestId |
string |
Explanation: Request ID returned by the OBS server. |
Id2 |
string |
Explanation: Request ID2 returned by the OBS server. |
Indicator |
string |
Explanation: Error code details returned by the OBS server. |
Parameter |
Type |
Description |
---|---|---|
RequestId |
string |
Explanation: Request ID returned by the OBS server |
Bucket |
string |
Explanation: Bucket name |
KeyMarker |
string |
Explanation: Object name to start with when listing multipart uploads. This parameter corresponds to KeyMarker in the request. |
UploadIdMarker |
string |
Explanation: Upload ID to start with when listing multipart uploads. This parameter corresponds to UploadIdMarker in the request. |
NextKeyMarker |
string |
Explanation: Object name to start with for the next multipart upload listing request. This parameter is returned if some results were not returned. You can set KeyMarker in the next request to the returned value to list the remaining results. |
NextUploadIdMarker |
string |
Explanation: Upload ID to start with for the next multipart upload listing request. This parameter is used together with NextKeyMarker. This parameter is returned if some listing results were not returned. You can set UploadIdMarker of the next request to the returned value to list the remaining multipart uploads. |
MaxUploads |
number |
Explanation: Maximum number of multipart uploads that can be listed. This parameter corresponds to MaxUploads in the request. |
IsTruncated |
boolean |
Explanation: Whether all results are returned in the response. Value range:
|
Prefix |
string |
Explanation: Object name prefix in multipart uploads. This parameter corresponds to Prefix in the request. It defines the 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 that contain logs/day1, logs/day2, or logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all multipart uploads in the bucket will be returned. |
Delimiter |
string |
Explanation: Used to group object names involved in multipart uploads. This parameter corresponds to Delimiter 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 placed separately into another CommonPrefixes with bbcd as the prefix. |
Uploads |
Upload[] |
Explanation: List of multipart uploads. For details, see Table 6. |
EncodingType |
string |
Explanation: Encoding type for Key in the response. If Key in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode Key. |
Parameter |
Type |
Description |
---|---|---|
Key |
string |
Explanation: Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object 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. |
UploadId |
string |
Explanation: Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. |
Initiator |
Explanation: Initiator of the multipart upload. For details, see Table 7. |
|
Owner |
Explanation: Account ID of the object owner. For details, see Table 8. |
|
StorageClass |
Explanation: Storage class of the object involved in the multipart upload. For details about the storage classes, see Table 9. |
|
Initiated |
string |
Explanation: Time when the multipart upload was initiated |
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
ID |
string |
Yes if used as a request parameter |
Explanation: Account (domain) ID of the initiator Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
DisplayName |
string |
No |
Explanation: Account name of the initiator Restrictions: The account name can contain 6 to 32 characters and must start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. Default value: None |
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
ID |
string |
Yes if used as a request parameter |
Explanation: Account (domain) ID of the owner Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
DisplayName |
string |
No |
Explanation: Account name of the owner Default value: None |
Constant |
Default Value |
Description |
---|---|---|
ObsClient.enums.StorageClassStandard |
STANDARD |
Standard storage class. Features low access latency and high throughput and is used for storing massive, frequently accessed (multiple times a month) or small objects (< 1 MB) requiring quick response. |
ObsClient.enums.StorageClassWarm |
WARM |
Infrequent Access storage class. Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. |
ObsClient.enums.StorageClassCold |
COLD |
Archive storage class. Used for storing rarely accessed (once a year) data. |
Code Examples
This example lists all multipart uploads for bucket examplebucket that have been initiated but not completed or aborted.
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 |
// Import the OBS library. // Use npm to install the client. const ObsClient = require("esdk-obs-nodejs"); // Use the source code to install the client. // var ObsClient = require('./lib/obs'); // Create an instance of ObsClient. const obsClient = new ObsClient({ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html. access_key_id: process.env.ACCESS_KEY_ID, secret_access_key: process.env.SECRET_ACCESS_KEY, // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. // security_token: process.env.SECURITY_TOKEN, // Enter the endpoint corresponding to the region where the bucket is located. CN-Hong Kong is used here in this example. Replace it with the one currently in use. server: "https://obs.ap-southeast-1.myhuaweicloud.com" }); async function listMultipartUploads() { try { const params = { // Specify the bucket name. Bucket: "examplebucket", // Specify an object. example/objectname is used in this example. Key: "example/objectname", // Specify the maximum number of multipart uploads that can be listed. 10 is used in this example. MaxUploads: 10 }; // List multipart uploads. const result = await obsClient.listMultipartUploads(params); if (result.CommonMsg.Status <= 300) { console.log("List mulitpart uploads successful with bucket(%s) !", params.Bucket); console.log("RequestId: %s", result.CommonMsg.RequestId); for (let i = 0; i < output.Uploads.length; i++) { const upload = output.Uploads[i]; console.log("Upload[%d]-OwnerId:%s, UploadId:%s, Key:%s, Initiated:%s", i, upload.Owner.ID, upload.UploadId, upload.Key, upload.Initiated); }; return; }; console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); console.log("Status: %d", result.CommonMsg.Status); console.log("Code: %s", result.CommonMsg.Code); console.log("Message: %s", result.CommonMsg.Message); console.log("RequestId: %s", result.CommonMsg.RequestId); } catch (error) { console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); console.log(error); }; }; listMultipartUploads(); |
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