Page updated Apr 29, 2024

Get file properties

You can get file properties and metadata without downloading the file

getProperties

1import { getProperties } from 'aws-amplify/storage';
2
3try {
4 const result = await getProperties({
5 path: 'public/album/2024/1.jpg',
6 // Alternatively, path: ({identityId}) => `protected/${identityId}/album/2024/1.jpg`
7 });
8 console.log('File Properties ', result);
9} catch (error) {
10 console.log('Error ', error);
11}
1import { getProperties } from 'aws-amplify/storage';
2
3try {
4 const result = await getProperties({
5 key: 'album/2024/1.jpg',
6 options: {
7 accessLevel: 'guest', // defaults to `guest` but can be 'private' | 'protected' | 'guest'
8 targetIdentityId: 'xxxxxxx' // ID of another user, if accessLevel is `protected`
9 }
10 });
11 console.log('File Properties ', result);
12} catch (error) {
13 console.log('Error ', error);
14}

The properties and metadata will look similar to the below example

1{
2 path: 'public/album/2024/1.jpg',
3 contentType: 'image/jpeg',
4 contentLength: 6873,
5 eTag: '\"56b32cf4779ff6ca3ba3f2d455fa56a7\"',
6 lastModified: Wed Apr 19 2023 14:20:55 GMT-0700 (Pacific Daylight Time) {},
7 metadata: { owner : 'aws' }
8}
1{
2 key : 'album/2024/1.jpg',
3 contentType: 'image/jpeg',
4 contentLength: 6873,
5 eTag: '\"56b32cf4779ff6ca3ba3f2d455fa56a7\"',
6 lastModified: Wed Apr 19 2023 14:20:55 GMT-0700 (Pacific Daylight Time) {},
7 metadata: { owner : 'aws' }
8}

To get the metadata in result for all APIs you have to configure user defined metadata in CORS.

Learn more about how to setup an appropriate CORS Policy.