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?
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.