Ad
Why Does Listing Objects In An S3 Bucket's Folder Using AWS SDK For JavaScript Returns Empty Contents Array But KeyCount Greater Than One?
I have a bucket in S3 called myBucketName. It has one folder called myFolderName and is containing one file myFile.
I try to list the objects in the folder like so:
s3.listObjectsV2({
Bucket: 'myBucketName',
Delimiter: "/",
Prefix: 'myFolderName',
})
With the response
{
IsTruncated: false,
Contents: [],
Name: 'myBucketName',
Prefix: 'myFolderName',
Delimiter: '/',
MaxKeys: 1000,
CommonPrefixes: [ { Prefix: 'myFolderName/' } ],
KeyCount: 1
}
How come the Contents
array is empty even though KeyCount
is 1? I would have expected to contain one item with Key == 'myFolderName/myFile'
What should I do to get the desired result, i.e. a list of the objects in the folder?
Ad
Answer
Use Prefix: 'myFolderName/'
(with the forward slash /
) when listing the objects. It's telling you there is only one "object" (a folder) in the folder you're asking about.
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad