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

Page updated Aug 15, 2024

Copy files

Note: You can only copy files up to 5GB in a single operation

You can copy an existing file to a different path within the storage bucket using the copy API.

The copy method duplicates an existing file to a designated path and returns an object {path: 'destPath'} upon successful completion.

import { copy } from 'aws-amplify/storage';
const copyFile = async () => {
try {
const response = await copy({
source: {
path: 'album/2024/1.jpg',
// Alternatively, path: ({identityId}) => `album/{identityId}/1.jpg`
},
destination: {
path: 'shared/2024/1.jpg',
// Alternatively, path: ({identityId}) => `shared/{identityId}/1.jpg`
},
});
} catch (error) {
console.error('Error', err);
}
};

Cross identity ID copying is only allowed if the destination path has the the right access rules to allow other authenticated users writing to it.

Specify a bucket or copy across buckets / regions

You can also perform an copy operation to a specific bucket by providing the bucket option. This option can either be a string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.

import { copy } from 'aws-amplify/storage';
const copyFile = async () => {
try {
const response = await copy({
source: {
path: 'album/2024/1.jpg',
// Specify a target bucket using name assigned in Amplify Backend
// or bucket name from console and associated region
bucket: 'assignedNameInAmplifyBackend'
},
destination: {
path: 'shared/2024/1.jpg',
// Specify a target bucket using name assigned in Amplify Backend
// or bucket name from console and associated region
bucket: {
bucketName: 'generated-second-bucket-name',
region: 'us-east-2'
}
}
});
} catch (error) {
console.error('Error', err);
}
};

In order to copy to or from a bucket other than your default, both source and destination must have bucket explicitly defined.

Copy source and destination options

OptionTypeDefaultDescription
pathstring |
({ identityId }) => string
RequiredA string or callback that represents the path in source and destination bucket to copy the object to or from
bucketstring |
{ bucketName: string;
region: string; }
Default bucket and region from Amplify configurationA string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.

Read more at Configure additional storage buckets.