Empty `body` and `files` request properties
See original GitHub issueI feel like I must be doing something extremely silly here, but can replicate my problem in a really simple app following your examples. Perhaps there is something really weird with my node setup.
Platform: OSX El Capitan Node Version: v5.12.0 (I’ve also nvm-ed and tried with v6.7.0, same outcome)
Expected Result:
POST multipart/form-data
requests with the multer middleware should add body
and files
properties to the request object with the data.
What happens for me:
Empty req.body
or req.files
data from POST requests. Multer throws no errors and returns empty object and array for them respectively.
I’ve made a simple repo that shows my setup: https://github.com/jamsinclair/multer-test
My server js is literally:
(I’ve tried using different api methods, .array()
, .single('name')
, .none()
etc, still the same outcome)
var app = require('express')();
var multer = require('multer');
var upload = multer({ dest: './uploads' })
app.post('/upload', upload.any(), function (req, res, next) {
console.log('body data:', req.body);
console.log('files data:', req.files);
res.sendStatus(200);
});
app.listen(9000, function () {
console.log('Listening on port 9000');
});
Example payload being sent via Postman:
POST /upload HTTP/1.1
Host: localhost:9000
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache
Postman-Token: 40d74092-2b02-12c4-b213-6ecd515ff61f
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="foo"
bar
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="name"
multer
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Issue Analytics
- State:
- Created 7 years ago
- Comments:16
Top GitHub Comments
I ended up using solution from @wcandillon article https://medium.com/@wcandillon/uploading-images-to-firebase-with-expo-a913c9f8e98d
It will be much simpler to just use one middleware, but it doesn’t work in Firebase cloud 😦
After much digging around finally stumbled upon my answers here http://stackoverflow.com/a/10765244/5179940
The body data for the
multipart/form-data
requests must end with CLRF(\r\n
) line endings.The body data boundaries have an extra
--
prepended For example, The header with boundary defined:Note how the body data boundaries have an extra
--
prepended Body Data:Issue resolved for myself.