bodyParse.text() is for body body string . From the documentation:
bodyParser.text (option)
Returns middleware that parses all bodies as a string ...
Since you are loading binary data (like a zip file) using bodyParser.text() , it converts the body of your buffer to utf-8 string . Thus, you will lose some data for binary files, and the zip file may be unreadable.
For a binary file, use bodyParser.raw() , which will give you a buffer in req.body , and you can safely save that buffer to a file.
app.use(bodyParser.raw({ type: 'application/octet-stream', limit: '10mb' }));
To download files, you really need to look at multer , which works for multipart/form-data content type.
source share