Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
S3 listObjects recursively node

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Amazon S3 is a flat object storage system that does not use directories. Instead, the Key (filename) of an object includes the full path of the object. Directories magically 'appear' based on the paths of existing objects, and can later disappear when there are no objects in that path.

A CommonPrefix is the Amazon S3-equivalent of showing a sub-directory.

When calling ListObjects() with a Delimiter parameter (eg Delimiter='/'), a list of subdirectories is returned in the CommonPrefixes field. This allows recursion through directories much like traditional storage systems. If you remove this parameter, all objects with the given Prefix will be returned, rather than just the 'current directory'.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!