request: Content-Length header is not set when using the form library
I tried to upload a file using the form library like this:
var r = request.post(options, cb),
form = r.form();
form.append('image', fs.createReadStream('/tmp/testimg.jpg'));
My server (nginx as reverse proxy in front of Apache) then throws a 411. I then tried to set the Content-Length manually like this:
var r = request.post(options, cb),
form = r.form();
form.append('image', fs.createReadStream('/tmp/testimg.jpg'));
r.setHeader('Content-Length', form.getLengthSync());
But then the server script (PHP) throws a UPLOAD_ERR_PARTIAL (The file was only partially uploaded) error. So i guess, the Content-Length is still wrong.
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 20 (4 by maintainers)
This WILL work with cookie and correct Content-Length !
+1 still not working…
I got a mix of @mikehaertl and @lildemon solutions to work properly:
For some reason, in my tests
form.getLength(source) returns the rightlengthwhereasform.getLengthSync(source) returnslengthminus 12@mikeal - I have proposed a fix for this on our fork at: https://github.com/postmanlabs/postman-request/pull/13
What do you think? Is it worth a PR here?
I am using multiparty and request module together. Here is code example:
Here I am uploading the user uploaded file to another server via streaming i.e., without saving a temporary file.
But on the PHP server no file is uploaded. $_FILES array is empty.
Please help.