Dart
Dart
S3 Delete Bucket Object
See more Amazon S3 (new) Examples
Deletes an object in a bucket.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final rest = CkRest();
// Connect to the Amazon AWS REST server.
final bTls = true;
final port = 443;
final bAutoReconnect = true;
rest.connect('s3.amazonaws.com', port, bTls, bAutoReconnect);
// ----------------------------------------------------------------------------
// Important: For buckets created in regions outside us-east-1,
// there are three important changes that need to be made.
// See Working with S3 Buckets in Non-us-east-1 Regions for the details.
// ----------------------------------------------------------------------------
// Provide AWS credentials for the REST call.
final authAws = CkAuthAws();
authAws.accessKey = 'AWS_ACCESS_KEY';
authAws.secretKey = 'AWS_SECRET_KEY';
authAws.serviceName = 's3';
rest.setAuthAws(authAws);
// Set the bucket name via the HOST header.
// In this case, the bucket name is "chilkat100".
rest.host = 'chilkat100.s3.amazonaws.com';
// This example deletes the object named "Abc.ics"
final sbResponse = CkStringBuilder();
try {
rest.fullRequestNoBodySb('DELETE', '/Abc.ics', sbResponse);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// If successfully deleted, the response status code is 204 and the response body text will be empty.
final statusCode = rest.responseStatusCode;
print('Response status code = $statusCode');
print('Response text = ');
print(sbResponse.getAsString());
}