expressjs / connect-multiparty

connect middleware for multiparty

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set maxFilesSize can't response error

youxiachai opened this issue · comments

I found if set

var express = require('express'),
    multipart = require('connect-multiparty'),
    multipartMiddleware = multipart({
        maxFilesSize : 2 * 1024
    })
    http = require('http');

var app = express()

app.set('port', 5000);
app.get('/', function (req, res) {
    res.send('<form method="post" enctype="multipart/form-data">'
        + '<p>Title: <input type="text" name="title" /></p>'
        + '<p>Image: <input type="file" name="image" /></p>'
        + '<p><input type="submit" value="Upload" /></p>'
        + '</form>');
});

app.post('/', multipartMiddleware, function (req, res) {
    res.send('ok');
});

app.use(function (err, req, res, next){
    console.log('handle error')
    console.error(err.stack);
    res.send(500, 'Something broke!');
})


http.createServer(app).listen(app.get('port'), function () {
    console.log('env: ' + process.env.NODE_ENV);
    console.log('Express server listening on port ' + app.get('port'));
});

if I upload more than 1 MB(but work ~40KB) size file ,It will throw err in console, but it will not send response !!

so browser will hang request !!

I added a test for this, but the test passes. Can you provide a test case that demonstrates your problem?

if file small ,it will work well,but large file will hang request,although it throw error

commented

qq20140524112628
qq20140524113341

commented

How to fix?

How to fix?

We need someone (perhaps you?) to give us a patch that fixes the issue, or a single complete JS file we can run and hit the issue so we can investigate. So far no one has offered us either of those.

commented
var express = require('express');
var app = express();
app.set('port', 3000);

var serveStatic = require('serve-static');
app.use(serveStatic('./public', {'index': ['default.html', 'default.htm']}));

var multiparty = require('connect-multiparty');
app.post("/upload",
    multiparty({
        uploadDir:"./tmp",
        maxFilesSize:1 * 1024 * 1024
    }),
    function(req,res){
        res.end("ok..");
    }
);
var http = require('http');
http.createServer(app).listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
});

html
http://lannisport-nodejs-87124.apne1.nitrousbox.com:3000/connect-multiparty.html

commented
<form name="form1" action="/upload" method="post" enctype="multipart/form-data" >
    <input type="file" name="upload" multiple="multiple">
    <input type="submit" value="submit">
</form>
commented

qq20140524133510

Please refer to pillarjs/multiparty#69 for the progress on this issue.

Please try the current master version of this module and tell me if the issue is fixed or not, please. You can install with npm install andrewrk/connect-multiparty

commented

OK,Thanks.

@285858315 did it work? Any verdict yet?

Please try version 1.0.4 of this module.

@dougwilson I test 1.0.4 it work well (limit 2M upload file 100M, not hang request)! thanks fix this bug!

@youxiachai thank you for confirming this does seems to fix the issue :)

@dougwilson I am still having this issue in v3.3

using form.on 'file',
and form.on 'error'

something I missed?

currently I'm doing this, but not sure if it's efficient.

form.on 'file', (name, file) -> 
  if file.size > conf.app.upload_size
    return ex.throw new ex.Validation('file is too large'), res

Hi @mryangyu it's possible it's not the same issue as here. Can you open up a new issue in the repo? I'll be happy to help. If you have any more code to share that would also be helpful :)

If you are talking about events, I think you meant to file the issue in this repo, actually: https://github.com/andrewrk/node-multiparty

Update: I see the code you put and it's probably not correct; I would need to see more, though, but just in a new issue, please :)