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

Documents with Image and File fields don't clean up orphaned files when they are removed #162

Open
JedWatson opened this issue Feb 6, 2014 · 5 comments
Labels

Comments

@JedWatson
Copy link
Member

As mentioned by @alanshaw in #161.

One solution would be to create a 'cleanup' method on Documents that gets the files and images referenced in any LocalFile, S3File, CloudinaryImage (etc) fields and deletes them.

It could potentially check for references to the same files in the same field in other documents in the collection first to make sure it didn't incorrectly remove files in use by other documents (e.g. because of duplication or copy/paste) - this may cause poor performance on unindexed fields in larger collections though.

We could also prompt in the Admin UI when Items are deleted to run the cleanup method (if the List has file fields in it), so the user has the choice.

Don't want to be too aggressive about automatically cleaning up but it would be good to have the option for Keystone to clean up after itself over time.

@jdarling
Copy link
Contributor

jdarling commented Feb 9, 2014

I like the prompt the admin user approach. Seems like it would be the easiest to implement in the near future. Reference checks tend to get messy and are difficult to get right.

@jamlen
Copy link
Contributor

jamlen commented Feb 10, 2014

+1 for the UI Prompt

@alanshaw
Copy link
Contributor

I can't attach a schema post remove hook to cover this use case because Automattic/mongoose#1241

So this is really needed.

@yinear
Copy link

yinear commented Nov 17, 2014

The remove file button is not functional also.
How can I force the file to be removed ?
Like this?
XXX.schema.post('delete', function(next) {
//do some force remove
});

@molomby
Copy link
Member

molomby commented Oct 5, 2017

If this is an immediate and serious problem for anyone, one of the ways you can (probably?) work around it is discussed over here.

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

7 participants