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

Partially uploaded files are not removed when fileSize kicks in #194

Closed
qqilihq opened this issue Aug 7, 2015 · 10 comments
Closed

Partially uploaded files are not removed when fileSize kicks in #194

qqilihq opened this issue Aug 7, 2015 · 10 comments
Labels

Comments

@qqilihq
Copy link

qqilihq commented Aug 7, 2015

I'm using the fileSize property to set a maximum upload size limit. In case, the uploaded file size exceeds the specified fileSize limit, the transfer is interrupted (as expected), but the partially uploaded file still exists on disk.

I feel, that such files should be removed automatically (also concerning the fact, that there seems to be no way of retrieving the path of partially uploaded files within my callback methods).

@LinusU
Copy link
Member

LinusU commented Aug 7, 2015

I think I might have squashed that bug last night, or maybe not... Which version of multer are you using?

@qqilihq
Copy link
Author

qqilihq commented Aug 7, 2015

Hey Linus, thank you for your feedback; I've just updated to 1.0.3, and now the file is deleted in case it exceeds the fileSize limit.

However: The solution which you were describing in #186 for custom error handling does not work any longer with 1.0.3:

var upload = multer({ limits: { fileSize: 1024 * 1024 * 1024 } });

app.post('/upload', upload.single('file'), function (req, res) {
  // will now also be called in case the limit was reached
  res.send({ result: 'ok' });
});

app.use(function (err, req, res, next) {
  if (err.code === 'LIMIT_FILE_SIZE') {
    // will not be reached any more :(
  }
});

As I was also relying on the custom error handling: Any solution on getting that fixed?

@ghost
Copy link

ghost commented Aug 7, 2015

I am having the same issue as @qqilihq where the err.code is not being set to 'LIMIT_FILE_SIZE' when the limit file size is exceeded in 1.0.3.

A workaround is to perform the following check

if(typeof req.file === "undefined")  {
   // There was an error with the upload        
}

@qqilihq
Copy link
Author

qqilihq commented Aug 7, 2015

@PokerCurve Thank you for the suggestion, however in that case I cannot distinguish between the cases where (1) the limit was exceeded or (2) no file was attached at all. And I would really like to do that for better error messaging.

@LinusU
Copy link
Member

LinusU commented Aug 10, 2015

This should absolutely work, I'm sorry to have broke it.

This is very related to nodejs/node#2323 which there is a proposed fix for. Unfortunately I'm on vacation on a remote island with very bad internet connection and limited time to devote to this.


Sorry, I just found this message sitting in the textbox, I forgot to hit "comment" 😕

@LinusU LinusU added the bug label Aug 11, 2015
@qqilihq
Copy link
Author

qqilihq commented Aug 12, 2015

Hi Linus, I've fixed the issue and sent you a pull request. Enjoy your vacation.

@LinusU
Copy link
Member

LinusU commented Aug 14, 2015

@qqilihq Could you try #205 and see if it fixes it for you?

@qqilihq
Copy link
Author

qqilihq commented Aug 17, 2015

@LinusU Yes, I can confirm that it solves the issue in my case.

@LinusU
Copy link
Member

LinusU commented Sep 19, 2015

This should be fixed by #205 and released on npm as version 1.0.5 🚀

Please reopen if issue persists.

@LinusU LinusU closed this as completed Sep 19, 2015
@terwi
Copy link

terwi commented Jul 5, 2018

Hi,
is there a way to stop uploading if the size of the FOLDER not the file is exceeding a defined limitation

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

3 participants