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

How to limit file maxsize and form parse error not handle #324

Closed
clues opened this issue Jan 19, 2015 · 16 comments
Closed

How to limit file maxsize and form parse error not handle #324

clues opened this issue Jan 19, 2015 · 16 comments

Comments

@clues
Copy link

clues commented Jan 19, 2015

Hi, this a code in my project:
form.uploadDir = conf.getConf().storageRoot;
form.keepExtensions = true;
form.maxFieldsSize = 1 * 1024;
form.encoding = 'utf-8';

1, The property maxFieldsSize is single file max data size? if is, it's not work.
2, If set uploadDir value is unexist directory, progress can't trigger form.on('error',Fun), will
throw a err and i not catch it. So try catch not work also.

@gabeio
Copy link
Contributor

gabeio commented Jan 19, 2015

maxFieldsSize relates to only <input type=text />

Limits the amount of memory all fields together (except files)

try checking file.size for the size being bigger than you want & if it is throw an error...

@luin
Copy link

luin commented Jan 24, 2015

It would be better to check the file size during receiving the file instead of after the file is uploaded, so I consider maxFileSize is necessary.

@gabeio
Copy link
Contributor

gabeio commented Jan 24, 2015

you can:

form.on('fileBegin', function(name,file) {
    if(file.size < X){
        throw new error; // this should stop the file upload (maybe before it begins; i don't know the internal part)
    }
})

@clues
Copy link
Author

clues commented Jan 26, 2015

yes,i'm agree with @luin, Nginx upload model and S3 all have this function.
@gabeio
form.on('fileBegin', function(name,file) {
if(file.size < X){
throw new error; // this should stop the file upload (maybe before it begins; i don't know the internal part)
}
})
the file.size is whole file size? i worry only first part of chunks size, if client use header 'Transfer-Encoding',
i'm not familiar with http upload stream

@gabeio
Copy link
Contributor

gabeio commented Jan 26, 2015

I believe the browser has to tell the server the size in advanced... and that should be the size. But as for wanting new features the developer/owner of this has kinda abandoned/doesn't have enough time anymore to work on this. Therefore if you want the feature you'll have to implement it yourself. I have just been trying to help out with issues as much as I can because I did like the library until I needed better support myself so I switched to multer and body-parser combo (as multer only does multi-part and body-parser only does basic form data)

@OrangeDog
Copy link
Contributor

Use the fileBegin (to check what the client claims) and progress (to see how much is actually sent) events to limit upload size.
Can either throw, calll form._error or change path to '/dev/null'.

@gabeio
Copy link
Contributor

gabeio commented Jan 26, 2015

thank you @OrangeDog for confirming and the addition.

@clues
Copy link
Author

clues commented Jan 27, 2015

Thank all. I have test, 'fileBegin' get the file.size is 0, and 'progress' like to solve the problem, but progress is reference whole form body, i only care about file receivedBytes. So, must implement by myself.

@luin
Copy link

luin commented Jan 27, 2015

@clues I have switched to multer, which is able to limit the file size

@clues
Copy link
Author

clues commented Jan 27, 2015

nodejs-bug
i add field maxFileSize to form, and add compare code in handlePart function, it work.

@pensierinmusica
Copy link

+1 Agree with @luin this should really be provided natively by the formidable library. One must be able to easily limit the max file size! Any progress? I know multer provides this, but I'm using koa-body which relies on formidable.

@addedjacky
Copy link

rewrite the onPart function

@rfink
Copy link

rfink commented Apr 6, 2016

+1 very much needed for koa-body

@we-zhang
Copy link

+1, using koa-body now.

@jaydenseric
Copy link

For some time there has been a good pull request that adds max upload size for files; it only needs to be merged: #357.

@xarguments
Copy link
Collaborator

AFAIU maxFileSize solves the problem, and the issue can be closed now.
If I'm mistaken, feel free to reopen/comment it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants