headBucket method
This operation is useful to determine if a bucket exists and you have
permission to access it. The operation returns a 200 OK
if
the bucket exists and you have permission to access it. Otherwise, the
operation might return responses such as 404 Not Found
and
403 Forbidden
.
To use this operation, you must have permissions to perform the
s3:ListBucket
action. The bucket owner has this permission by
default and can grant this permission to others. For more information
about permissions, see Permissions
Related to Bucket Subresource Operations and Managing
Access Permissions to Your Amazon S3 Resources.
May throw NoSuchBucket.
Parameter bucket
:
The bucket name.
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 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.
Implementation
Future<void> headBucket({
required String bucket,
String? expectedBucketOwner,
}) async {
ArgumentError.checkNotNull(bucket, 'bucket');
final headers = <String, String>{
if (expectedBucketOwner != null)
'x-amz-expected-bucket-owner': expectedBucketOwner.toString(),
};
await _protocol.send(
method: 'HEAD',
requestUri: '/${Uri.encodeComponent(bucket)}',
headers: headers,
exceptionFnMap: _exceptionFns,
);
}