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.

Remove single file

You can remove a single file using Amplify.Storage.remove with the key and its associated access level:

Future<void> removeFile() async {
try {
final result = await Amplify.Storage.remove(
path: const StoragePath.fromString('public/file.txt'),
).result;
safePrint('Removed file: ${result.removedItem.path}');
} on StorageException catch (e) {
safePrint(e.message);
}
}

Remove multiple Files

You can remove multiple files using Amplify.Storage.removeMany with the keys, the files to be removed in a batch should have the same access level:

Future<void> remove() async {
try {
final result = await Amplify.Storage.removeMany(
paths: [
const StoragePath.fromString('public/file-1.txt'),
const StoragePath.fromString('public/file-2.txt'),
],
).result;
safePrint('Removed files: ${result.removedItems}');
} on StorageException catch (e) {
safePrint(e.message);
}
}