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
Post a Comment