listParts method

Future<ListPartsOutput> listParts({
  1. required String bucket,
  2. required String key,
  3. required String uploadId,
  4. String? expectedBucketOwner,
  5. int? maxParts,
  6. int? partNumberMarker,
  7. RequestPayer? requestPayer,
})

Lists the parts that have been uploaded for a specific multipart upload. This operation must include the upload ID, which you obtain by sending the initiate multipart upload request (see CreateMultipartUpload). This request returns a maximum of 1,000 uploaded parts. The default number of parts returned is 1,000 parts. You can restrict the number of parts returned by specifying the max-parts request parameter. If your multipart upload consists of more than 1,000 parts, the response returns an IsTruncated field with the value of true, and a NextPartNumberMarker element. In subsequent ListParts requests you can include the part-number-marker query string parameter and set its value to the NextPartNumberMarker field value from the previous response.

For more information on multipart uploads, see Uploading Objects Using Multipart Upload.

For information on permissions required to use the multipart upload API, see Multipart Upload API and Permissions.

The following operations are related to ListParts:

Parameter bucket : The name of the bucket to which the parts are being uploaded.

When using this API with an access point, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this operation with an access point through the AWS SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using Access Points in the Amazon Simple Storage Service Developer Guide.

When using this API with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using this operation using S3 on Outposts through the AWS SDKs, you provide the Outposts bucket ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on Outposts in the Amazon Simple Storage Service Developer Guide.

Parameter key : Object key for which the multipart upload was initiated.

Parameter uploadId : Upload ID identifying the multipart upload whose parts are being listed.

Parameter expectedBucketOwner : The account id of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP 403 (Access Denied) error.

Parameter maxParts : Sets the maximum number of parts to return.

Parameter partNumberMarker : Specifies the part after which listing should begin. Only parts with higher part numbers will be listed.

Implementation

Future<ListPartsOutput> listParts({
  required String bucket,
  required String key,
  required String uploadId,
  String? expectedBucketOwner,
  int? maxParts,
  int? partNumberMarker,
  RequestPayer? requestPayer,
}) async {
  ArgumentError.checkNotNull(bucket, 'bucket');
  ArgumentError.checkNotNull(key, 'key');
  _s.validateStringLength(
    'key',
    key,
    1,
    1152921504606846976,
    isRequired: true,
  );
  ArgumentError.checkNotNull(uploadId, 'uploadId');
  final headers = <String, String>{
    if (expectedBucketOwner != null)
      'x-amz-expected-bucket-owner': expectedBucketOwner.toString(),
    if (requestPayer != null) 'x-amz-request-payer': requestPayer.toValue(),
  };
  final $query = <String, List<String>>{
    'uploadId': [uploadId],
    if (maxParts != null) 'max-parts': [maxParts.toString()],
    if (partNumberMarker != null)
      'part-number-marker': [partNumberMarker.toString()],
  };
  final $result = await _protocol.sendRaw(
    method: 'GET',
    requestUri:
        '/${Uri.encodeComponent(bucket)}/${key.split('/').map(Uri.encodeComponent).join('/')}',
    queryParams: $query,
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  final $elem = await _s.xmlFromResponse($result);
  return ListPartsOutput(
    bucket: _s.extractXmlStringValue($elem, 'Bucket'),
    initiator: _s
        .extractXmlChild($elem, 'Initiator')
        ?.let((e) => Initiator.fromXml(e)),
    isTruncated: _s.extractXmlBoolValue($elem, 'IsTruncated'),
    key: _s.extractXmlStringValue($elem, 'Key'),
    maxParts: _s.extractXmlIntValue($elem, 'MaxParts'),
    nextPartNumberMarker:
        _s.extractXmlIntValue($elem, 'NextPartNumberMarker'),
    owner: _s.extractXmlChild($elem, 'Owner')?.let((e) => Owner.fromXml(e)),
    partNumberMarker: _s.extractXmlIntValue($elem, 'PartNumberMarker'),
    parts: $elem.findElements('Part').map((c) => Part.fromXml(c)).toList(),
    storageClass:
        _s.extractXmlStringValue($elem, 'StorageClass')?.toStorageClass(),
    uploadId: _s.extractXmlStringValue($elem, 'UploadId'),
    abortDate:
        _s.extractHeaderDateTimeValue($result.headers, 'x-amz-abort-date'),
    abortRuleId:
        _s.extractHeaderStringValue($result.headers, 'x-amz-abort-rule-id'),
    requestCharged: _s
        .extractHeaderStringValue($result.headers, 'x-amz-request-charged')
        ?.toRequestCharged(),
  );
}