Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Dec 4, 2024

Remove files

Files can be removed from a storage bucket using the remove API. If a file is protected by an identity Id, only the user who owns the file will be able to remove it.

Amplify.Storage.remove(
StoragePath.fromString("public/myUploadedFileName.txt"),
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"),
{ Log.i("MyAmplifyApp", "Successfully removed: ${it.path}") },
{ Log.e("MyAmplifyApp", "Remove failure", it) }
)
try {
val result = Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"))
Log.i("MyAmplifyApp", "Successfully removed: ${result.path}")
} catch (error: StorageException) {
Log.e("MyAmplifyApp", "Remove failure", error)
}
RxAmplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"))
.subscribe(
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);

Remove files from a specified bucket

You can also perform a remove operation to a specific bucket by providing the bucket option. You can pass in a string representing the target bucket's assigned name in Amplify Backend.

StorageBucket secondBucket = StorageBucket.fromOutputs("secondBucket");
StorageRemoveOptions options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build();
Amplify.Storage.remove(
StoragePath.fromString("public/myUploadedFileName.txt"),
options,
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
val secondBucket = StorageBucket.fromOutputs("secondBucket")
val options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build()
Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options,
{ Log.i("MyAmplifyApp", "Successfully removed: ${it.path}") },
{ Log.e("MyAmplifyApp", "Remove failure", it) }
)
val secondBucket = StorageBucket.fromOutputs("secondBucket")
val options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build()
try {
val result = Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
Log.i("MyAmplifyApp", "Successfully removed: ${result.path}")
} catch (error: StorageException) {
Log.e("MyAmplifyApp", "Remove failure", error)
}
StorageBucket secondBucket = StorageBucket.fromOutputs("secondBucket");
StorageRemoveOptions options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build();
RxAmplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
.subscribe(
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);

Alternatively, you can also pass in an object by specifying the bucket name and region from the console.

BucketInfo bucketInfo = new BucketInfo("second-bucket-name-from-console", "us-east-2");
StorageBucket secondBucket = StorageBucket.fromBucketInfo(bucketInfo);
StorageRemoveOptions options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build();
Amplify.Storage.remove(
StoragePath.fromString("public/myUploadedFileName.txt"),
options,
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
val bucketInfo = BucketInfo("second-bucket-name-from-console", "us-east-2")
val secondBucket = StorageBucket.fromBucketInfo(bucketInfo)
val options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build()
Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options,
{ Log.i("MyAmplifyApp", "Successfully removed: ${it.path}") },
{ Log.e("MyAmplifyApp", "Remove failure", it) }
)
val bucketInfo = BucketInfo("second-bucket-name-from-console", "us-east-2")
val secondBucket = StorageBucket.fromBucketInfo(bucketInfo)
val options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build()
try {
val result = Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
Log.i("MyAmplifyApp", "Successfully removed: ${result.path}")
} catch (error: StorageException) {
Log.e("MyAmplifyApp", "Remove failure", error)
}
BucketInfo bucketInfo = new BucketInfo("second-bucket-name-from-console", "us-east-2");
StorageBucket secondBucket = StorageBucket.fromBucketInfo(bucketInfo);
StorageRemoveOptions options = StorageRemoveOptions.builder()
.bucket(secondBucket)
.build();
RxAmplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
.subscribe(
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);