-
Notifications
You must be signed in to change notification settings - Fork 29
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
Setting to delete files after successful upload #16
Comments
Yes, I have no way of really knowing that you have acted on the file and done what you wanted. I guess I could add a method that cleans the files up but you would still need to call it when your process is done. |
Didn't mean to close it :) |
That's OK. And a method that could be called to delete the files after processing is done is not a bad idea... I find having to use cronjobs a bit unsatisfactory |
It created in my public directory some unwanted folders like '3d6c3049-839b-40ce-9aa3-b76f08bf140b' -> file -> myfile I am not sure how to remove this. |
I suppose a file could be sent to any post route in my application and it would then remain in the tmp directory eternally. The best behaviour from my point of view would be to cleanup after the request by default. When I want to keep the file beyond the request I'd move it to a safe location. Maybe can do it with middleware (pseudocode). Finish is triggered after success, close is triggered on failure. module.exports = (req, res, next) => {
const files = req.files || {};
function cleanupFiles () {
res.removeListener('finish', cleanupFiles);
res.removeListener('close', cleanupFiles);
// delete files/dirs
}
res.on('finish', cleanupFiles);
res.on('close', cleanupFiles);
next();
}; |
If you go with the default clean up, please allow an option to prevent it.
Thanks, |
So after the file (or image) has been uploaded to the server and the server has done whatever it needs to do with it (e.g. save to database or store in AWS, etc), the NodeJS server should delete the files from the
tmp
directory (or wherever they were saved)The text was updated successfully, but these errors were encountered: