Page updated Nov 14, 2023

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.

import 'package:amplify_flutter/amplify_flutter.dart'; Future<void> copyGuestFileToPrivate({ required String sourceKey, required String destinationKey, }) async { try { final result = await Amplify.Storage.copy( source: StorageItemWithAccessLevel( storageItem: StorageItem(key: sourceKey), accessLevel: StorageAccessLevel.guest, ), destination: StorageItemWithAccessLevel( storageItem: StorageItem(key: destinationKey), accessLevel: StorageAccessLevel.private, ), ).result; safePrint('Copied file: ${result.copiedItem.key}'); } on StorageException catch (e) { safePrint('Error copying file: ${e.message}'); rethrow; } }
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}