Replies: 3 comments 9 replies
-
Hi Mattias, It's simply a quesiton of accessing the:
In order to connect to the former, you need access credentials, and in order to "connect" to the file, you need, minimally, the object "key". This key, is mostly held (for Shrine use cases) in a database record. I don't have enough details, but from your lambda, you'll have to access the relevant database record, or otherwise get a hold of the s3 object's key, in order to "connect" to it. Once you have those details, connecting to the file should be trivial. |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, you want to save attachment data do the database for files not uploaded by Shrine? You should be able to do this by generating a uploaded_file = Shrine.uploaded_file(id: "key", storage: :store, metadata: { ... })
book.cover_image_attacher.set(uploaded_file)
book.save If you want to extract metadata in the process, you could use the Shrine.plugin :refresh_metadata uploaded_file = Shrine.uploaded_file(...)
uploaded_file.refresh_metadata!
book.cover_image_attacher.set(uploaded_file)
book.save |
Beta Was this translation helpful? Give feedback.
-
Here is another way to tell a shrine model about an existing file on S3: book.cover_image_attacher.change( book.cover_image_attacher.uploaded_file(store: :storage, id: "some_id/something.jpg") ) That one will do more standard lifecycle management -- not sure if that will include extracting metadata and various other hooks normally run on a "normal" upload, etc. I think this method is as similar as you can get to uploading a file, except for an existing file, with all (maybe?) of the normal stuff that would happen on uploading a file still happening. I asked a similar question in a larger more confusing thread I started here: #579 (reply in thread). I wound up finding this answer myself, with some hints from others. Curious what @janko thinks about this method vs |
Beta Was this translation helpful? Give feedback.
-
Hi,
Thanks for a great library! I was wondering if you have any idea on how to "connect" with new files not being uploaded from our application? I'll give you an example
Normal procedure
What I'm trying to achieve
2. Let's say we add files directly to S3, from a Lambda function or that someone sends an email with a cover image of an book. How would we go on to "connect" this to an already existing book in our system if the file is already in an bucket?
All the best,
Mattias
Beta Was this translation helpful? Give feedback.
All reactions