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

221
Views
Creating S3 Files in a Loop - Node.JS + AWS-SDK

I'm trying to create a set of files from their binary data received from an API call but the files are never created, but the promise.then function is called:

for(var i in fileSections){
    var content = fileSections[i].split((/Content-Length: [0-9]*/));
    var fileName = content[0].split('filename=')[1].trim();
    var file = {Bucket : 'MyBucket', Key: ROOT+'/'+FOLDER+'/'+SUBFOLDER+'/'+fileName, Body: content[1]};
    console.log('Creating file: '+file.Key );
***CODE RUNS TO AT LEAST HERE FOR EACH FILE***
    promises.push(S3.upload(file));
}
***.THEN FUNCTION FIRES***
Promise.all(promises).then(confirmProposal()).catch(function(err){context.done(err);});

Earlier on in the process I create a file in S3 using this code:

var application = {Bucket : 'MyBucket', Key: ROOT+'/'+FOLDER+'/'+SUBFOLDER+'/application.xml', Body: fileSections[0]};
S3.upload(application,function(err,data)
    {
        ...files are created in here on a successful response ...
    });

Which works and the file is created. Does anyone know what I'm doing wrong?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Change this line:

promises.push(S3.upload(file));

to this:

promises.push(S3.upload(file).promise());

The AWS NodeJS SDK functions don't return a promise directly. For example the S3.upload() function returns an AWS.S3.ManagedUpload object. You have to call .promise() on the returned object to get a promise.

about 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!