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

Page updated May 1, 2024

Remove files

Remove a file

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

import 'package:amplify_flutter/amplify_flutter.dart';
Future<void> removeFile({
required String key,
required StorageAccessLevel accessLevel,
}) async {
try {
final result = await Amplify.Storage.remove(
key: key,
options: StorageRemoveOptions(
accessLevel: accessLevel,
),
).result;
safePrint('Removed file: ${result.removedItem.key}');
} on StorageException catch (e) {
safePrint('Error deleting file: ${e.message}');
rethrow;
}
}

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:

import 'package:amplify_flutter/amplify_flutter.dart';
Future<void> removePrivateFiles({
required List<String> keys,
}) async {
try {
final result = await Amplify.Storage.removeMany(
keys: keys,
options: const StorageRemoveManyOptions(
accessLevel: StorageAccessLevel.private,
),
).result;
safePrint('Removed files: ${result.removedItems}');
} on StorageException catch (e) {
safePrint('Error deleting files: ${e.message}');
rethrow;
}
}