Monday 30 March 2020

Can't access image from PUT request

I can't seem to figure out how I can access the image which is being sent in a put request using nodejs. At the moment I'm am using fs.writeFile:exports.uploadPhoto = async function (req, res) {fs.writeFile(fileName, req.body, 'binary', function (err) {if (err) throw err;respond(res, 200);});}However if I check the length of req.body it says its 0 and it writes 0 bytes to the file. In the bodyParser I have:app.use(bodyParser.json());app.use(bodyParser.raw({ type: 'text/plain' }));app.use(bodyParser.raw({ type: [ 'image/jpeg', 'image/gif', 'image/png' ], limit: '20mb' }));The body type I am using in postman is binary with an image attached. I am really confused as to what is going on. Any help would be greatly appreciated.

Submitted March 31, 2020 at 04:10AM by personalfnzthrowaway

No comments:

Post a Comment