Listing Files in a Bucket

Files in a bucket can be listed provided an S3 client instance and a bucket name.

const params = {
Bucket: "my-bucket",
MaxKeys: 20
};
s3.listObjectsV2(params, function (err, data) {
if (err) {
console.log("Error when listing objects", err);
} else {
console.log("Success when listing objects", data);
}
});

An example of a typical response is provided below.

{ IsTruncated: false,
Contents:
[ { Key: 'hello-world.gif',
LastModified: 2020-05-21T19:07:54.956Z,
ETag: '"-1"',
Size: 2078126,
StorageClass: 'STANDARD',
Owner: [Object] } ],
Name: 'my-team-bucket',
Prefix: '',
Delimiter: '',
MaxKeys: 20,
CommonPrefixes: [],
KeyCount: 1 }

Each file in Fleek Storage can be identified through the Name of the bucket that contains it and the file’s unique Key.

We are here to help

We are happy to help get your website up and running. Please feel free to reach out on our website, in our Community Chat, on Twitter, or at [email protected]