I want to recursively get all the files in an S3 bucket folder.
I want to achieve the same behaviour as the ls -R command in Linux.
Here's an illustration
my_folder
|_abc
| |_abc_file.txt
| |_xyz
| |_xyz_file.txt
|
|_file.txt
Considering the above directory structure. if I do
const data = await s3.listObjectsV2({
Prefix: 'my_folder/',
Bucket: bucket,
Delimiter: `/`,
}).promise();
Currently, I get the following data:
-CommonPrefixes: ["abc"]
-Contents:["file.txt"]
The expected behaviour is:
- Contents: ["abc/abc_file.txt", "abc/xyz/xyz_file.txt", "file.txt"]
I tried using ES6 generator functions and recursive functions to solve this problem and end up with a lot of messed up code.
I am using S3 node SDK