Dart
Dart
S3 Delete File
See more Amazon S3 Examples
Demonstrates how to delete a remote file (object) on the Amazon S3 service.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
// Insert your access key here:
http.awsAccessKey = 'AWS_ACCESS_KEY';
// Insert your secret key here:
http.awsSecretKey = 'AWS_SECRET_KEY';
final bucketName = 'chilkattest';
final objectName = 'starfish.jpg';
http.keepResponseBody = true;
try {
http.s3DeleteObject(bucketName, objectName);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
if (http.lastStatus != 204) {
print('Status code = ${http.lastStatus}');
print(http.lastResponseBody);
print('Failed.');
return;
}
// 204 is the success response status.
// When successful, the response body will be empty.
print('Status code = ${http.lastStatus}');
print('Success. Object deleted.');
}