--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/9dffea91-7d85-4faa-a9b8-d0f33ff6cfc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you're caching the image links, it's best to generate public links, ones which don't include "X-Amz-Expires" or other query params. You can do that by passing `public: true` to `UploadedFile#url`:photo.image[:thumbnail].url#=> "https://your-bucket.s3.amazonaws.com/path/to/image.jpg?X-Amz-Expires=900&X-Amz-Signature=71977cb69a18f61f3ce5326021b51b8466b2ce0594313d5a0a23be949f6280ac&..."photo.image[:thumbnail].url(public: true)Kind regards,Janko
On Wed, Apr 26, 2017 at 9:11 PM, <advme...@gmail.com> wrote:
Hello,I enjoy Shrine a lot, the modular construction make a lot of sense, and the look and feel is cleaner to my eyes. So thank for that!My class Post contains thumbnails hosted on S3 with the help of Shrine, and everything works perfectly.I then implemented caching in rails, especially for index actions and each Post is encapsulated inside a cache tag with a proper key.I encounred 403 errors while loading (GET) the thumbnail, so I suspect my cache (90 mins) to mess with the "cache_control" and "expires" options specified inside Shrine::Storage::S3 like so :store: Shrine::Storage::S3.new(prefix: "store", upload_options: { acl: 'public-read', cache_control: 'public, max-age=315569260', expires: 604800 }, **s3_options), # permanent# cache_control 10years & expires 7daysMoreover, I saw that the presigned url generated by Shrine has a X-Amz-Expires of 15 mins, the maximum value authorized by AWS being 7 days.This is not directly a Shrine question, but since AWS presigned url is quite new for me, would you mind orienting me to the right direction using it with Shrine and caching ?Should I act on the X-Amz-Expires to set the max value of 7 days and, if yes, how can I set this param ? Or should I play with the cache_control & expires ?Thank you In advance for all your work and help.Kind Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/4f765609-7876-454c-b373-cc1115c30397%40googlegroups.com.
class MyUploader < Shrine
plugin :module_include
file_methods do
def url(**options)
return super unless storage.is_a?(Shrine::Storage::S3) && storage_key == :store
Rails.cache.fetch("url:#{storage_key}:#{id}", expires_in: 6.days) do
super(expires_in: 7.days, **options)
end
end
end
Shrine.plugin :module_includeShrine.file_module do
def url(**options) return super unless storage.is_a?(Shrine::Storage::S3) && storage_key == 'store'
Rails.cache.fetch("url:#{storage_key}:#{id}", expires_in: 6 * 24 * 60 * 60) do super(expires_in: 7 * 24 * 60 * 60, **options) end endend
Shrine.plugin :module_includeShrine.file_module do def url(**options) return super unless storage.is_a?(Shrine::Storage::S3) && storage_key == 'store' Rails.cache.fetch("url:#{storage_key}:#{id}", expires_in: 6 * 24 * 60 * 60) do super(expires_in: 7 * 24 * 60 * 60, **options) end endend