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

Setting to delete files after successful upload #16

Open
sylvan-d-ash opened this issue Feb 24, 2017 · 6 comments
Open

Setting to delete files after successful upload #16

sylvan-d-ash opened this issue Feb 24, 2017 · 6 comments

Comments

@sylvan-d-ash
Copy link

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)

@davglass
Copy link
Contributor

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.

@davglass davglass reopened this Feb 27, 2017
@davglass
Copy link
Contributor

Didn't mean to close it :)

@sylvan-d-ash
Copy link
Author

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

@ashjha1
Copy link

ashjha1 commented Sep 25, 2017

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.

@Kequc
Copy link

Kequc commented Feb 7, 2018

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();
};

@danosaure
Copy link

If you go with the default clean up, please allow an option to prevent it.

cleanup: false

Thanks,

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

No branches or pull requests

5 participants