Replies: 1 comment 3 replies
-
I would be very interested to know what are the issues surrounding why a column cannot simply be saved to a new record? new_record.image_data = old_record.image_data
Janko built Shrine for this very purpose: to allow for perfect flexibility in getting Shrine to do exactly what you want it to do. I haven't looked too closely into it, but I would prefer Attacher#destroy overridden for a specific uploader. But this may be due to my incorrect understanding of the API that you want. The only complication i can see is if two records are some how deleting the same folder? I would be curious to see the finished result. |
Beta Was this translation helpful? Give feedback.
-
So I have a use case I'm considering whether/how to use shrine for... let's dip my toe in the new Github Discussion forum, see what happens!
I will be creating HLS video -- a prepared HLS video consists of a manifest file ending in
.m3u8
, possibly some secondary.m3u8
manifests, and dozens (or more) of.ts
segment files.It's really only the primary
manifest.m3u8
that my app needs to know about. I probably won't be uploading all the files through shrine/the app -- some external process will create the HLS files in a storage location.So why might I want to use shrine at all?
I know there are ways to store multiple files in "derivatives" in an array/Hash-like structure. And indeed this HLS set could be considered the derivative of an existing file...
But for simplicity, what I'm thinking is creating an additional shrine attachment, and using it to store/reference only the primary
.m3u8
file -- this is really all the app needs to refer to (although for lifecycle management... see below). It just seems like a simpler and more straightforward thing to implement and debug and maintain to me.I think this will mostly work out, but there are two somewhat weird parts:
Can I assign an existing file to a shrine attachment?
An external process is going to create these files in a storage location. So I'd like to assign that location to my Rails model/shrine attachment, without doing an upload or anything, just assign the location attachment, like the hash with a
storage
andid
key...The file already exists inside a "storage" shrine knows about, I just need to save it's location on the model without triggering any upload process or other analysis.
It seems like this should be do-able, but I'm having trouble figuring out what way of doing it will play well with shrine.
Can I make delete/destroy delete the whole directory?
I'm thinking the attachment will only know about the primary
manifest.m3u8
file, and this is ordinarily all the app needs to know about/refer to.BUT, if shrine decides to delete the attachment for any reason... I want it to delete the contents of the whole directory that that referenced file is in.
Fortunately, at least some shrine adapters now have a delete_prefixed method that can be used to delete a directory, great. The ones I will be using do, great.
Is it totally insane to write a little local shrine "plugin" that will override deletion to trigger
delete_prefixed
on the prefix/directory the file is in, whenever a deletion happens? I guess by over-riding UploadedFile#delete? (Or maybe Attacher#destroy, but I thinkUploadedFile#delete
is probably better, and the plugin system does seem to let us do it with theFileMethods
module? )Is this a reasonable idea?
In general, does this approach make sense? Is there a better way to do it?
Beta Was this translation helpful? Give feedback.
All reactions