richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

Unabled to delete tempFiles while using limitHandler #295

Open Xenope opened 2 years ago

Xenope commented 2 years ago

We are using the tempFolder and dealing with the file size limit with the limitHandler.

We are doing some logging and then rejecting the error : res.status(413); res.json(error);

but it's impossible to delete (fs.unlink()) the file currently in the temp folder.

The code that cleans up the temporaryFolder (cleanUp()) is never called, moreover the file is still open because the writeStream.end(); of the cleanUp() method is never called making it unabled to delete it on windows until the node process is over.

One simple solution would be to pass the cleanUp() method as a fourth argument to the limitHandler() method.

Anybody have experienced this issue or have an other workaround?

PS: On linux the file is deleted event tough the writeStream.end(); has not been called.