formidable: Use formidable upload files, always get "Error Request Aborted"
- I use Express(3.6.0) + formidable(latest) for upload files to S3.
- When I submit post , then I always got
Error Request Aborted. - incoming_form.js:
IncomingForm.prototype.parse = function(req, cb) {
.......
.......
.......
req
.on('aborted', function() {
self.emit('aborted');
self._error(new Error('Request aborted'));
})
.......
.......
.......
}
[Error: Request aborted]
child process: Request aborted
Error: Request aborted
at IncomingMessage.<anonymous>
(/node_modules/formidable/lib/incoming_form.js:107:19)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:465:12)
I want to know why I got aborted and how to debug it.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 2
- Comments: 52 (11 by maintainers)
I just published formidable-serverless - it imports formidable as a dependency and modifies the handlers to support preprocessed request bodies (built-in to many serverless environments).
I’m using it in production with Firebase @BrodaNoel @brodwen83 @lborgman @nicholasstephan
The usage/API is exactly the same. Hope that helps.
I’m trying to use formidable in a firebase function, and am getting this error for every request.
try to delete this in your app.js.
app.use(express.bodyParser());I have sovled this proplem.
Getting rid of the app.use(bodyParser.json()); helped.
@programmerpinggiran from your logs it seems like the error is coming from elsewhere.
While the
abortedevent is captured atformidable-serverless/lib/index.js:102:19:The event is emitted elsewhere:
... events.js:180:13... domain.js:422:20... _http_server.js:441:9etc.Check those files (file:line:col)Never mind those are node’s files.You’re using PM2 so I’m assuming you’re not in a serverless environment. Will need more information:
@tunnckoCore error still exist
It is the client that is aborting, not the server. It’s an error you can always get and which you must handle. It’s not a bug in formidable.
sorry, i mean removing koa-body’s bodyParser, i use formiable@1.2.2 and latest koa2. Now everything works, thx
@programmerpinggiran there’s a lot going on there… have you tried unit testing the API endpoint? Once you know the specific fail cases it’ll be easier to debug.
While formidable-serverless should be fine alongside body-parser, if you’re not in a serverless environment I would separate body-parser from formidable. This is because body-parser can emit its own errors and make it difficult to debug in the mixup, and the double parsing can be an unnecessary performance drag. You can do this by providing body-parser as middleware to only the API endpoints that need it (excluding the endpoint that uses formidable).
The @Amit-A 's
formidable-serverlesspackage worked nicely for me in firebase cloud functions. No code changes was needed, just import the package where formidable was required.@tunnckoCore that could be a nice way of doing it, but I wonder about versioning risk… if there’s a breaking change in formidable, and we pass the new formidable to the function, it could return a broken parse method vs. the current implementation: importing formidable, enforcing the version in package.json, then exporting it.
to disable body-parser for multipart/form-data in your router
exmple solution of nodejs
@Amit-A Thx, that really helped
@Amit-A thanks, this is a great library.
our android client using okhttp
@tunnckoCore ill try it and report here after few days later thanks anyway
I have problem, i have nodejs api retreive upload from android phone… This error show randomly… Sometimes succed, and some time error showing
One way to solve it is to using a GET request instead and disguise it as a POST or PUT by sending params. For example, on the front end side, via angular it would be: $http.get(‘/fetchComments’, {params: payLoadObj}).then…
And to retrieve it from your server file: req.query
I’ve seen this problem when using some php server along with the express stuff (nginx with fpm module as reverse proxy, for say). In that case I got rid of the php-fpm module and got lucky: my files started to upload. Looking at the nginx logs I discovered that the connection was being reset for whatever reason I don’t know. Now I’m getting the same issue on another server where some guy installed apache and vstfptd. Before that, everything was working like a charm.
I would try to narrow the problem down (also talking to myself on this point) to see what is exactly the problem here.
Any ideas on how to trace the problem in an e2e fashion?
edit: using express 4.16.2 and express-formidable 1.0.0
+1 Removing the express bodyparser didn’t helped either