listObjects method

Future<ListObjectsOutput> listObjects({
  1. required String bucket,
  2. String? delimiter,
  3. EncodingType? encodingType,
  4. String? expectedBucketOwner,
  5. String? marker,
  6. int? maxKeys,
  7. String? prefix,
  8. RequestPayer? requestPayer,
})

Returns some or all (up to 1,000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK response can contain valid or invalid XML. Be sure to design your application to parse the contents of the response and handle it appropriately. The following operations are related to ListObjects:

May throw NoSuchBucket.

Parameter bucket : The name of the bucket containing the objects.

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 delimiter : A delimiter is a character you use to group keys.

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 marker : Specifies the key to start with when listing objects in a bucket.

Parameter maxKeys : Sets the maximum number of keys returned in the response. By default the API returns up to 1,000 key names. The response might contain fewer keys but will never contain more.

Parameter prefix : Limits the response to keys that begin with the specified prefix.

Parameter requestPayer : Confirms that the requester knows that she or he will be charged for the list objects request. Bucket owners need not specify this parameter in their requests.

Implementation

Future<ListObjectsOutput> listObjects({
  required String bucket,
  String? delimiter,
  EncodingType? encodingType,
  String? expectedBucketOwner,
  String? marker,
  int? maxKeys,
  String? prefix,
  RequestPayer? requestPayer,
}) async {
  ArgumentError.checkNotNull(bucket, 'bucket');
  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>>{
    if (delimiter != null) 'delimiter': [delimiter],
    if (encodingType != null) 'encoding-type': [encodingType.toValue()],
    if (marker != null) 'marker': [marker],
    if (maxKeys != null) 'max-keys': [maxKeys.toString()],
    if (prefix != null) 'prefix': [prefix],
  };
  final $result = await _protocol.send(
    method: 'GET',
    requestUri: '/${Uri.encodeComponent(bucket)}',
    queryParams: $query,
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return ListObjectsOutput.fromXml($result.body);
}