How should I handle the files stored in /tmp after use?
See original GitHub issueSupport plan
- which support plan is this issue covered by? (e.g. Community, Sponsor, or Enterprise): Community
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): probably
Context
- node version: v12.16.3
- module (formidable) version: ^1.2.2
- environment (e.g. node, browser, native, OS): WSL2, Ubuntu 18.04 LTS
- used with (i.e. popular names of modules): express
- any other relevant information:
What are you trying to achieve or the steps to reproduce?
This is more of a question than a bug. I would like to know what is the recommended way to handle the temporary files that are not in use anymore.
The temporary files that get stored in the /tmp folder don’t get deleted after finished use. So I guess I have to do it myself. So my main question is, should I delete the file even though an error occurred processing the request by parse()
:
formidable().parse(req, async (err, fields, files) => {
if (!err) {
// I'm going to remove the file here, e.g. fs.unlink(files.someFile.path, someCallback)
} else {
// My question is should I also do it here, or does formidable remove the file automatically when there is an error??
}
next();
});
I really don’t want to risk temporary files getting piled up in production. And I know that files in /tmp folder gets deleted after a reboot, but my server will not get rebooted very often I think.
What was the result you got?
Again this issue is more of a question than a bug report.
What result did you expect?
It would be nice if formidable removed the file automatically after use, but again this issue is more of a question than a bug report.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (3 by maintainers)
@AndysonDK In that case you want to manually delete the temp file right after the request gets fulfilled, that’s how I personally go about body parsing with formidable:
asyncFormidable.js
If you find a better solution let us know.
Ah, yea. It would be good Formidable to handle that too. But that’s for now.
Also, in future, it won’t write to disk by default so it will disappear.