Is there a way to save the ETag value from Amazon S3 using the Shrine gem?

62 Views Asked by At

I am using the Shrine gem to upload files to Amazon S3. Is there any way to retrieve the ETag value for a file and save it to the database after it has been uploaded? Ideally I would like to access the ETag value in the upload response to avoid having to do another request to Amazon.

I see ETag referenced a number of times in the gem but am not seeing a straightforward way: https://github.com/search?q=repo%3Ashrinerb%2Fshrine%20etag&type=code

1

There are 1 best solutions below

1
Ankush Jain On

I am not a Ruby on Rails developer, but here is something that I found might be helpful to you.

As per Shrine 2.17.0 documentation - Other improvements:

The derivation_endpoint, rack_response, and download_endpoint plugins now include ETag in the headers of responses, preventing the Rack::ETag middleware from buffering the response body.

So, you can use Rack Response plugin to convert an UploadedFile object into a triple consisting of status, headers, and body. From there, you can retrieve the ETag value from the headers.