Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set maxFilesSize can't response error #5

Closed
youxiachai opened this issue Mar 18, 2014 · 17 comments
Closed

set maxFilesSize can't response error #5

youxiachai opened this issue Mar 18, 2014 · 17 comments
Labels

Comments

@youxiachai
Copy link

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 !!

@youxiachai youxiachai changed the title set maxFilesSize can't handle error set maxFilesSize can't response error Mar 18, 2014
@andrewrk
Copy link
Member

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

@youxiachai
Copy link
Author

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

@285858315
Copy link

qq20140524112628
qq20140524113341

@285858315
Copy link

How to fix?

@dougwilson
Copy link
Contributor

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.

@285858315
Copy link

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

@285858315
Copy link

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

@285858315
Copy link

qq20140524133510

@dougwilson
Copy link
Contributor

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

@dougwilson
Copy link
Contributor

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

@285858315
Copy link

OK,Thanks.

@dougwilson
Copy link
Contributor

@285858315 did it work? Any verdict yet?

@dougwilson
Copy link
Contributor

Please try version 1.0.4 of this module.

@youxiachai
Copy link
Author

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

@dougwilson
Copy link
Contributor

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

@mryangyu
Copy link

@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

@dougwilson
Copy link
Contributor

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 :)

@expressjs expressjs locked and limited conversation to collaborators Jul 31, 2014
@dougwilson dougwilson added the bug label Jul 31, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants