putBucketVersioning method
- required String bucket,
- required VersioningConfiguration versioningConfiguration,
- String? contentMD5,
- String? expectedBucketOwner,
- String? mfa,
Sets the versioning state of an existing bucket. To set the versioning state, you must be the bucket owner.
You can set the versioning state with one of the following values:
Enabled—Enables versioning for the objects in the bucket. All objects added to the bucket receive a unique version ID.
Suspended—Disables versioning for the objects in the bucket. All objects added to the bucket receive the version ID null.
If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
If the bucket owner enables MFA Delete in the bucket versioning
configuration, the bucket owner must include the x-amz-mfa
request
header and the Status
and the
MfaDelete
request elements in a request to set the versioning
state of the bucket.
Related Resources
Parameter bucket
:
The bucket name.
Parameter versioningConfiguration
:
Container for setting the versioning state.
Parameter contentMD5
:
>The base64-encoded 128-bit MD5 digest of the data. You must use this
header as a message integrity check to verify that the request body was
not corrupted in transit. For more information, see RFC 1864.
For requests made using the AWS Command Line Interface (CLI) or AWS SDKs, this field is calculated automatically.
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 mfa
:
The concatenation of the authentication device's serial number, a space,
and the value that is displayed on your authentication device.
Implementation
Future<void> putBucketVersioning({
required String bucket,
required VersioningConfiguration versioningConfiguration,
String? contentMD5,
String? expectedBucketOwner,
String? mfa,
}) async {
ArgumentError.checkNotNull(bucket, 'bucket');
ArgumentError.checkNotNull(
versioningConfiguration, 'versioningConfiguration');
final headers = <String, String>{
if (contentMD5 != null) 'Content-MD5': contentMD5.toString(),
if (expectedBucketOwner != null)
'x-amz-expected-bucket-owner': expectedBucketOwner.toString(),
if (mfa != null) 'x-amz-mfa': mfa.toString(),
};
await _protocol.send(
method: 'PUT',
requestUri: '/${Uri.encodeComponent(bucket)}?versioning',
headers: headers,
payload: versioningConfiguration.toXml('VersioningConfiguration'),
exceptionFnMap: _exceptionFns,
);
}