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

Page updated May 1, 2024

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