meteor-autoform-file icon indicating copy to clipboard operation
meteor-autoform-file copied to clipboard

Files never deleted?

Open sf-wind opened this issue 10 years ago • 15 comments
trafficstars

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?

sf-wind avatar Dec 27 '14 07:12 sf-wind

At the moment, the old files are not deleted.

This is something that should be fixed in a future version.

yogiben avatar Dec 31 '14 12:12 yogiben

@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.

bastiaanterhorst avatar Feb 01 '15 09:02 bastiaanterhorst

@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.

bastiaanterhorst avatar Feb 01 '15 09:02 bastiaanterhorst

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.

yogiben avatar May 03 '15 18:05 yogiben

This being implemented would be nice :)

fpaboim avatar May 13 '15 19:05 fpaboim

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).

AdamSutch avatar May 13 '15 19:05 AdamSutch

+1

suryaiiit avatar Aug 03 '15 17:08 suryaiiit

+1

mehrdadarvin avatar Sep 03 '15 19:09 mehrdadarvin

+1

jsbranco avatar Oct 25 '15 02:10 jsbranco

+1

bluxu avatar Jan 01 '16 17:01 bluxu

One possible solution is to do upload only when form is saved not on each file input change.

mpowaga avatar Jan 12 '16 23:01 mpowaga

Or a system that allows for orphaned file cleanup ( cron maybe ? )

spunkedy avatar Feb 15 '16 09:02 spunkedy

author not solved this problem? He no longer support this project?

dshitik avatar Oct 11 '16 07:10 dshitik

is there any workaround?

juzt3 avatar Dec 22 '16 01:12 juzt3

+1

ntorgov avatar Jan 11 '17 15:01 ntorgov