JavaScript SDK

List buckets

1
await s3.listBuckets().promise();
Copied!

List objects

List objects in root folder

1
await s3.listObjectsV2({
2
Bucket: 'BUCKET',
3
Delimeter: '/',
4
}).promise();
Copied!

List objects in the folder

1
await s3.listObjectsV2({
2
Bucket: 'BUCKET',
3
Delimeter: '/',
4
Prefix: 'my-folder'
5
}).promise();
Copied!

Get files metadata

1
const result = await s3.headObject({
2
Bucket: 'BUCKET',
3
Key: 'folder/file-name.txt',
4
}).promise();
5
6
/*
7
{
8
Metadata: {key: 'value'},
9
ContentLength: 123,
10
ETag: '...',
11
...
12
}
13
*/
Copied!

Edit objects metadata

Note that you can not change values of these metadatas: file-hash, storage,location. When you set MetadataDirective: 'REPLACE' any existing metadatas will be overridden. So if you want to edit only some of metadatas then include existing metadatas too.
1
await s3.copyObject({
2
Bucket: 'BUCKET',
3
Key: 'file.txt',
4
CopySource: 'BUCKET/file.txt',
5
Metadata: {
6
'key': 'value',
7
'key2': 'value2'
8
},
9
MetadataDirective: 'REPLACE'
10
}).promise()
Copied!

Make object private or public

1
await s3.putObjectAcl({
2
Bucket: 'BUCKET',
3
Key: 'folder/file-name.txt',
4
ACL: 'public-read',
5
}).promise()
6
7
await s3.putObjectAcl({
8
Bucket: 'BUCKET',
9
Key: 'folder/file-name.txt',
10
ACL: 'private'
11
}).promise()
Copied!

Delete an object

1
await s3.deleteObject({
2
Bucket: 'BUCKET',
3
Key: 'folder/file-name.txt',
4
}).promise();
Copied!