Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda