Page updated Jan 16, 2024

Get file properties

You can get file properties and metadata without downloading the file using getProperties API from aws-amplify/storage

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

The format of the response will look similar to the below example

{ key : "key", contentType: "image/jpeg", contentLength: 6873, eTag: "\"56b32cf4779ff6ca3ba3f2d455fa56a7\"", lastModified: Wed Apr 19 2023 14:20:55 GMT-0700 (Pacific Daylight Time) {}, metadata: { owner : 'aws' } }
1{
2 key : "key",
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.