There are a lot of examples online regarding with file uploading for Node.js Express framework. But most of them are using multer. All of them are loading file from a form.
But my scenario is different. My app will pick an image from mobile phone and upload to server (by using cordova-file-transfer plugin in Ionic). In this case, I don't have a form at all. So that there is no req.files. Any suggestion? Thanks.
P.S: Here is the log in my server logs my http header:
{ host: 'localhost:3000',
'x-requested-with': 'XMLHttpRequest',
accept: '*/*',
'content-type': 'multipart/form-data; boundary=+++++org.apache.cordova.formBoundary',
'content-length': '23394',
'accept-language': 'en-us',
'accept-encoding': 'gzip, deflate',
connection: 'keep-alive',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13C75 (2079040640)' }
My server code:
app.post('/', multer({dest:'./uploads/'}).single('upl'),(req,res) => {
console.dir(req.headers)
console.dir(req.body)
res.status(204).end()
})
Apparently 'upl' is not defined in my case.
fileKeyfor cordova-plugin-file-transer toupl.