Remove files
Remove a file
You can remove a single file using Amplify.Storage.remove
with the key
and its associated access level:
1import 'package:amplify_flutter/amplify_flutter.dart';2
3Future<void> removeFile({4 required String key,5 required StorageAccessLevel accessLevel,6}) async {7 try {8 final result = await Amplify.Storage.remove(9 key: key,10 options: StorageRemoveOptions(11 accessLevel: accessLevel,12 ),13 ).result;14 safePrint('Removed file: ${result.removedItem.key}');15 } on StorageException catch (e) {16 safePrint('Error deleting file: ${e.message}');17 rethrow;18 }19}
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:
1import 'package:amplify_flutter/amplify_flutter.dart';2
3Future<void> removePrivateFiles({4 required List<String> keys,5}) async {6 try {7 final result = await Amplify.Storage.removeMany(8 keys: keys,9 options: const StorageRemoveManyOptions(10 accessLevel: StorageAccessLevel.private,11 ),12 ).result;13 safePrint('Removed files: ${result.removedItems}');14 } on StorageException catch (e) {15 safePrint('Error deleting files: ${e.message}');16 rethrow;17 }18}