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.
- make formidable work nicely with body-parser
- investigate what happens in case of abort What else do we need to do ?
@lborgman @BrodaNoel @brodwen83 & others.
Please try npm install formidable@canary - preview of v2. The API is almost the same, check the docs or open new issue if there's some problem.
@GrosSacASac lets see what's the state with latest (formidable@canary) versions of both Formidable and Express. Then we can just document how to use it with Express, more correctly.
koa2 meets the same problem, when using bodyParser with formidable. just remove it and I have sovled this proplem.
@spade69: just remove it
what you removed? Koa2 or Formidable@canary? Do you mean that the problem continue even with formidable@canary and latest koa2?
I'm going to publish v2 on 29th or 1st, so.. We may continue after that if it's still a problem.
@spade69: just remove it
what you removed? Koa2 or Formidable@canary? Do you mean that the problem continue even with
formidable@canaryand latest koa2?I'm going to publish v2 on 29th or 1st, so.. We may continue after that if it's still a problem.
sorry, i mean removing koa-body's bodyParser, i use [email protected] and latest koa2. Now everything works, thx
@spade69 Now everything works, thx
Cool! One last thing, do you mean with formidable@canary?
I'm going to fix that in #594 and v2.
@Amit-A Thx, that really helped
May be we need not delete the bodyParser.json(). I add bodyParser.raw({ type: 'multipart/form-data', limit: '10mb' }) and solved.
const jsonParser = bodyParser.json({ limit: '10mb' });
const formParser = bodyParser.raw({ type: 'multipart/form-data', limit: '10mb' });
app.post(url, formParser, jsonParser, [controller.func...] )
My problem was that after 70 to 90s request was aborted. I want to upload big files (2GB and more) to the api. But I was unable to upload bigger file then 2,8 GB on local host while testing.
I moved from koa2 to express (only because I understand express better). But still have the same error.
At the end I did try running tests in different node versions and I've succeed with version 15. Give it a try. I am using: "formidable": "1.2.2" and "express": "4.17.1", without bodyparser on upload route.
- Use recent version of Node to have nice default settings.
- Use maxFileSize: 3 * 10 ** 9 option, to receive 3GB files and less
- Do not use bodyParser and formidable, only use formidable
- abort error can and will happen when a clients loses internet or navigates to another page
- listen for error events to avoid abort error to crash the server, example:
const server = http.createServer((request, response) => {
request.on(`error`, console.error.bind(console, `request error`));
response.on(`error`, console.error.bind(console, `response error`));
this works for me
const form = new formidable.IncomingForm({maxFileSize:20 * 1024 * 1024});