I have a multipart/form-data content type which I have to send over a POST request.
multipart data contains application/octet-stream, ie array of bytes.
I am using multer node module at the server side to process the incoming multipart data.
I am using multer.any() preparser to parse the incoming data.
I am not able to get the octet stream data in req.body.content parameter where "content" is the name parameter in the request header.
req.body.content returns empty.
When I add a filename parameter to the multipart request header, such as filename="content" and send the same octet stream, I can access the octet stream via req.files parameter.
But I dont want to send a filename parameter in the request header of multipart data, since I am not sending a file and only a payload.
Do I have to use a different preprocessor other than multer.any() to get the payload in req.body rather than req.filename?
Or do I have to use a different npm module other than multer to process octet stream in multipart data
I used multer.single
to get this done.
Here is my code snippet from the app.js file in the node
import multer from 'multer';
const upload = multer();
app.post('/your_api_url', upload.single('file'),(req, res) => {
// here req.file.buffer is the array buffer which contains the octet stream
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.