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

bugs for limitHandler and Number of file you can upload #155

Closed
Truth1984 opened this issue Jul 3, 2019 · 8 comments
Closed

bugs for limitHandler and Number of file you can upload #155

Truth1984 opened this issue Jul 3, 2019 · 8 comments
Labels

Comments

@Truth1984
Copy link

Truth1984 commented Jul 3, 2019

So basically there are two bugs.

  1. If I set useTempFiles: true
    I want to remove the file after I hit the limit, and i will use
limitHandler: (req, res) => {
    // get the tempFilePath from req.files & remove the file from the disk
}

However, in this case, req.files == null, thus the file will remain on your disk then if I keep spamming, it will take all the space of your disk and crush the server.

2 I can't find anywhere to limit the amount of files of your uploads.
Thus, If I set fileSize limit to 100MB,
Even though you can write the proper code to check if truncated == true, and delete the file, but it happened after the user finish uploading right,
or use abortOnLimit: true then the tempfile will be kept on your server ...
I can upload few big chunks of files with few different computers from different ips, take over your disk and crush your server ?

@RomanBurunkov
Copy link
Collaborator

Invoking cleanup function in limit handler should help in case of

abortOnLimit: true

It can be added in to the processMultipart.js before lines 46, 50.

@Truth1984
Copy link
Author

And maybe add ext for file Obj ? so it's easy to check ext with mimetype and use mv() ?

@RomanBurunkov
Copy link
Collaborator

I didn't catch your update about ext.
Can you ellaborate it.

@Truth1984
Copy link
Author

example:

{
name: 'flower.png',
data: <Buffer >,
size: '10240',
ext:'png'
}

I can upload multiple files with different mimetype in a form right,
so it's easy to use mv()
as mv(path.resolve(dir, yourDesiredFilename+ext))

@RomanBurunkov
Copy link
Collaborator

I see, but probably it should be a separate issue.

Still thinking about how to resolve cleanup and limits issue.

@RomanBurunkov
Copy link
Collaborator

Hi @Truth1984 ,

I've published 1.1.6-alpha.1 version, where I've added cleanup function if upload was aborted because of file size limit.

@RomanBurunkov
Copy link
Collaborator

In 1.1.6-alpha.5 there is also new timeout check added for incoming data.
If no data comes during dataTimeout(default is 60000 msec ), middleware invokes cleanup method which close temp file stream and then delete temp file.

@RomanBurunkov
Copy link
Collaborator

Fixed:

  1. Upload timeout added
  2. Cleanup temp files if limit reached.

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

No branches or pull requests

2 participants