Skip to content

Instantly share code, notes, and snippets.

@RizkyRajitha

RizkyRajitha/promiseall.js

Last active Nov 26, 2019
Embed
What would you like to do?
var files = req.files;
var promisarr = [];//initialize promises array
function multiplefiles3(resobj) {
console.log(resobj.originalname);
var params = {
Bucket: "******",
Key: resobj.originalname,
Body: resobj.buffer
};
return s3bucket.upload(params).promise();
}
var uploadsize = 0;
files.map(file => {
uploadsize = uploadsize + file.size;
promisarr.push(multiplefiles3(file));//push individual promises to that array , i'll refer them as child promises
});
Promise.all(promisarr)//evoke Promise.all() function , i'll refer this as parent promise
.then(result => {
//this result is a array of objects from the fulfiled promise
})
.catch(err => console.log(err));//if any of those promises get reject this whole promise will be rejected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment