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