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

235
Views
Creación de archivos S3 en un bucle - Node.JS + AWS-SDK

Estoy tratando de crear un conjunto de archivos a partir de sus datos binarios recibidos de una llamada API, pero los archivos nunca se crean, pero se llama a la función promise.then:

 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);});

Anteriormente en el proceso, creo un archivo en S3 usando este código:

 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 ... });

Que funciona y se crea el archivo. ¿Alguien sabe lo que estoy haciendo mal?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cambia esta línea:

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

a esto:

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

Las funciones del SDK de AWS NodeJS no devuelven una promesa directamente. Por ejemplo, la función S3.upload() devuelve un objeto AWS.S3.ManagedUpload . Debe llamar a .promise() en el objeto devuelto para obtener una promesa.

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!