meteor-autoform-file
meteor-autoform-file copied to clipboard
Files never deleted?
I'm trying this module for the first time. It seems that the files in the database is never deleted. Here is what I did.
I create a form, attach a file to it, submit. The file is attached nicely. Great. Then I update the form, click "remove" to remove the original file. Then attach a different file, submit. The new file is attached. Great. Then I go into the mongodb database to search file records in cfs.files.filerecord collection. I find that the original file is still in the database.
The first thing I can think of is that I don't have remove permission defined correctly. But I have identical permissions for insert and remove:
Files.allow download : -> true insert : (userId, file) -> Roles.userIsInRole(userId, ['admin']) update : (userId, file) -> Roles.userIsInRole(userId, ['admin']) remove : (userId, file) -> Roles.userIsInRole(userId, ['admin'])
Did I do something wrong when using this package?
At the moment, the old files are not deleted.
This is something that should be fixed in a future version.
@yogiben I have a question regarding this: whats the purpose of the remove button if it does not actually remove files?
Would it not be better to take out the remove button (the [-] button will still be there to take out the file) and leave the deletion of the file up to the user. You can easily use an update hook to figure out which files are no longer associated with the object and do with them as you like.
I can create a PR if you support this idea.
@yogiben to clarify: I mean in the case of an array. When you only have a single file, of course you still need the remove button.
Sorry for the late reply @bastiaanterhorst
I'd want it to happen automatically without the user having to confirm.
When the user clicks remove, it cannot remove the file yet because the form hasn't been saved. There'd have to be some kind of hook when the form is saved, but I don't know how to make that work elegantly.
This being implemented would be nice :)
I use matb33:collection-hooks .after.update or .insert.update to remove the orphaned files. I get all the file _id's from the objects in that collection and remove any files not in that list with $nin. The only problem is it only cleans the "extra" files when someone updates (or inserts).
+1
+1
+1
+1
One possible solution is to do upload only when form is saved not on each file input change.
Or a system that allows for orphaned file cleanup ( cron maybe ? )
author not solved this problem? He no longer support this project?
is there any workaround?
+1