javascript - Express.js / Multer. Response being sent before onFileUploadComplete is complete -


i using following stuff file upload service:

onfileuploadstart: function (file) {         uploadpath = "";         imagedimensions = null;         console.log(file.originalname + ' starting upload...');     }, onfileuploadcomplete: function (file) {         uploadpath = file.path;         uploadpath = uploadpath.replace(/\\/g,"/");         console.log("upload complete. " + file.fieldname + ' uploaded  ' + file.path)         sizeof(file.path, function (err, dimensions) {             if (err){                 console.log("error, can't size of image! " + err);                 return;             }             else{                 imagedimensions = {                      width : dimensions.width,                     height: dimensions.height                 };                 console.log("size of image: width: " + imagedimensions.width + ". height: " + imagedimensions.height);             }          });     } 

and

app.post('/imageupload',function(req,res){   upload(req,res,function(err) {     console.log("response being send..");     if(err) {         return res.end("error uploading file.");     }     res.header("access-control-allow-origin", "*");     res.header("access-control-allow-headers", "x-requested-with");     res.json({         dimensions: imagedimensions,         path: uploadpath     }); }); 

});

from understand (https://stackoverflow.com/a/30458411/2742995) onfileuploadcomplete first processed before .post handler being executed. however, console shows:

a.jpg starting upload... upload complete. file uploaded uploadeddata\a1235412.jpg response being send.. size of image: width: 2835, height: 1654 

so seems right in middle of onfileuploadcomplete function .post handler being exectued..

any ideas how can solve this?

ok yeah got it... sizeof function used async.....

var dimensions = sizeof(file.path); 

is synced version.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -