Copy files
You can copy an existing file to a different location in your S3 bucket. User who initiates a copy operation should have read permission on the copy source file.
1import 'package:amplify_flutter/amplify_flutter.dart';2
3Future<void> copyGuestFileToPrivate({4 required String sourceKey,5 required String destinationKey,6}) async {7 try {8 final result = await Amplify.Storage.copy(9 source: StorageItemWithAccessLevel(10 storageItem: StorageItem(key: sourceKey),11 accessLevel: StorageAccessLevel.guest,12 ),13 destination: StorageItemWithAccessLevel(14 storageItem: StorageItem(key: destinationKey),15 accessLevel: StorageAccessLevel.private,16 ),17 ).result;18
19 safePrint('Copied file: ${result.copiedItem.key}');20 } on StorageException catch (e) {21 safePrint('Error copying file: ${e.message}');22 rethrow;23 }24}