Updated on 2024-11-26 GMT+08:00

Listing Uploaded Parts (SDK for Node.js)

If you have any questions during development, post them on the Issues page of GitHub.

Function

This API lists the uploaded parts in a specified bucket. This request must contain the multipart upload ID.

You can list the uploaded parts of a specified multipart upload or of all ongoing multipart uploads. For each listing request, OBS can list a maximum of 1,000 uploaded parts. If more than 1,000 parts were uploaded for a multipart upload, you need to send more than one request to list all uploaded parts. Assembled parts will not be listed.

Restrictions

  • To list uploaded parts, you must be the bucket owner or have the required permission (obs:object:ListMultipartUploadParts in IAM or ListMultipartUploadParts in a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
  • A maximum of 1,000 parts can be listed each time. If the upload of a specified ID contains more than 1,000 parts, InterfaceResult.IsTruncated in the response is true, indicating not all parts were listed. In such case, you can use InterfaceResult.NextPartNumberMarker to obtain the start position for the next listing.

Method

ObsClient.listParts(params)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

Bucket

string

Yes

Explanation:

Bucket name

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported, and the bucket attributes comply with those set in the first creation request.

Value range:

The value can contain 3 to 63 characters.

Default value:

None

Key

string

Yes

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.eu-west-101.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt.

Restrictions:

None

Value range:

The value can contain 1 to 1,024 characters.

Default value:

None

UploadId

string

Yes

Explanation:

Multipart upload ID, which is generated by initiating a multipart upload.

Restrictions:

None

Value range:

The value must contain 32 characters, for example, 000001648453845DBB78F2340DD460D8.

Default value:

None

PartNumberMarker

number

No

Explanation:

Part number the listing starts from.

Restrictions:

None

Restrictions:

OBS only lists parts with greater numbers than that specified by this parameter.

Default value:

None

MaxParts

number

No

Explanation:

Maximum number of parts that can be listed per page.

Restrictions:

If the specified value is greater than 1000, only 1,000 parts are returned.

Value range:

The value ranges from 1 to 1000.

Default value:

1000

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

Table 2 Responses

Type

Description

Table 3

NOTE:

This API returns a Promise response, which requires the Promise or async/await syntax.

Explanation:

Returned results. For details, see Table 3.

Table 3 Response

Parameter

Type

Description

CommonMsg

ICommonMsg

Explanation:

Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4.

InterfaceResult

Table 5

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.

Table 4 ICommonMsg

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.

Table 5 ListMultipartUploadsOutput

Parameter

Type

Description

RequestId

string

Explanation:

Request ID returned by the OBS server

Bucket

string

Explanation:

Bucket name

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.eu-west-101.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt.

UploadId

string

Explanation:

Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8.

Initiator

Initiator

Explanation:

Initiator of the multipart upload. For details, see Table 6.

Owner

Owner

Explanation:

Owner of the multipart upload, which is consistent with an initiator. For details, see Table 7.

StorageClass

StorageClassType

Explanation:

Storage class of the object obtained from assembling parts. For details about storage classes, see Table 8.

PartNumberMarker

number

Explanation:

Part number the listing begins from, which is consistent with that specified in the request.

NextPartNumberMarker

number

Explanation:

Part number to start with for the next part listing request. This parameter is returned if some parts were not listed. You can set PartNumberMarker to this value in the next request to list the remaining parts.

MaxParts

number

Explanation:

Maximum number of parts that can be listed per page, which is consistent with that specified in the request.

IsTruncated

boolean

Explanation:

Whether all results are returned in the response.

Value range:

  • true: Not all results are returned.
  • false: All results are returned.

Parts

Part[]

Explanation:

List of uploaded parts. For details, see Table 9.

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.

Table 6 Initiator

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

Table 7 Owner

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

Table 8 StorageClassType

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.

Table 9 Part

Parameter

Type

Description

PartNumber

number

Explanation:

Part number

LastModified

string

Explanation:

Time when a part was last modified, in UTC

ETag

string

Explanation:

ETag of a part. It is calculated by encoding the 128-bit MD5 value of the part using Base64.

Size

number

Explanation:

Size of the space occupied by a part

Code Examples

This example lists the parts that have been uploaded for a multipart upload.

 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
59
60
61
62
63
// 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/eu/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. EU-Dublin is used here in this example. Replace it with the one currently in use.
  server: "https://obs.eu-west-101.myhuaweicloud.eu"
});

async function listParts() {
    try {
        const params = {
            // Specify the bucket name.
            Bucket: "examplebucket",
            // Specify an object. example/objectname is used in this example.
            Key: "example/objectname",
            // Specify the multipart upload ID (00000188677110424014075CC4A77xxx in this example).
            UploadId: "00000188677110424014075CC4A77xxx",
            // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example.
            MaxKeys: 100,
        };
        // List uploaded parts.
        const result = await obsClient.listParts(params);
        if (result.CommonMsg.Status <= 300) {
            console.log("List part successful with bucket(%s) and object(%s)!", params.Bucket, params.Key);
            console.log('RequestId: %s', result.CommonMsg.RequestId);
            console.log('Bucket: %s', result.InterfaceResult.Bucket);
            console.log('Key: %s', result.InterfaceResult.Key);
            console.log('UploadId: %s', result.InterfaceResult.UploadId);
            console.log('PartNumberMarker: %s', result.InterfaceResult.PartNumberMarker);
            console.log('NextPartNumberMarker: %s', result.InterfaceResult.NextPartNumberMarker);
            console.log('MaxParts: %s', result.InterfaceResult.MaxParts);
            console.log('IsTruncated: %s', result.InterfaceResult.IsTruncated);
            console.log('StorageClass: %s', result.InterfaceResult.StorageClass);
            console.log('Initiator[ID]: %s', result.InterfaceResult.Initiator['ID']);
            console.log('Owner[ID]: %s', result.InterfaceResult.Owner['ID']);
            for (let i = 0; i < result.InterfaceResult.Parts.length; i++) {
                const part = result.InterfaceResult.Parts[i];
                console.log("Part[%d]-ETag:%s, PartNumber:%d, LastModified:%s, Size:%d",
                    i, part.PartNumber, part.LastModified, part.ETag, part.Size);
            };
            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);
    };
};

listParts();