richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

Question: how to access files immediately after upload (they are 0kb) #281

Closed yossielimelech closed 3 years ago

yossielimelech commented 3 years ago

I'm trying to access uploaded files inside the /uploads post route, I'm totally new to webdev so I'm not sure it that's even correct. when calling pdfutils inside the Promise.all I see that the files are 0kb if I continue to debug I finally see the files with the correct size.

How should I wait for the files to finish being copied and where it is best place to put the call to pdfutils?

for (let k in arr) { images[k] = path.resolve(path.join("./uploads", arr[k].name)) arr[k].mv(images[k], function (err) { let promise = new Promise(function (resolve, reject) { if (err) { reject(err); } else { resolve(); } }); uploads.push(promise); }) }

Promise.all(uploads).then(function () { res.json({ "status": "File uploaded!" }); console.log('inside post 3') pdfutils.merge(images).then(() => { // here I'm calling a method to merge some PDF's on the server. }) }).catch(function (err) { res.send(err); })