Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda