Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

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);
}
}