request: Chrome: formData can't be used because browsers can't use `on`.
I’m not sure if browser support is a goal of this lirbary, but when using this library via Browserify, you cannot make multipart/form requests.
Sample Request
request.put("/v3/uploads", {json:false, formData: {upload: file_handle}})
Error: Uncaught TypeError: self._form.on is not a function request.js:1134.
It looks like browsers don’t support the .on('error') call.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 7
- Comments: 21 (1 by maintainers)
I used multipart option and I set
headersoption with'content-type': 'multipart/form-data':@dafergu2, I had the same issue in electron app. But my solution was to get the
requestmodule fromwindowscope.I used this:
thanks @AlessandroPilastrini for your workaround. That works well. For reference, if you want to upload binary data (e.g. images), use this:
If you have an HTML5 upload, you can use a FileReader for the File. Example:
Had the same problem, couldn’t find a solution.
Ended up using superagent. Just sent an object with content-type
application/x-www-form-urlencodedI played around with many variations of request’s multipart configurations and could not get it to work with file data.
I quickly tried looking into the issue and it appears that there is quite a bit of the the
_formmember in the request object missing. I tried to fake theonevent and then moved on to faking a few other missing pieces. I gave up though as it appears there is a lot missing. I’m not sure if the issue is at the request, form-data or browserify layer. I’m a little concerned that that this type of thing isn’t under any code coverage.For now, I’ve gone ahead and decided to use needle as it just works 😉
@AlessandroPilastrini thanks, this worked as a nice workaround.
//changes made to line 1134. Please check out . requestjs.txt
//For further explaination , refer
http://stackoverflow.com/questions/32797573/alternative-to-onerror-this-onerror-bindthis-in-es6