1

I would like to use an active_storage representation in a mailer.

rails_blob_path(@post.photos.first.img).variant(resize: "300x300") don't work and all the links generated through rails_blob_path(@post.photos.first.img) expire in 5 mins.

Is there a way to generate permanent long lived urls?

Rails.application.routes.url_helpers.rails_blob_url(@post.photos.first.img.variant(resize: "300x300"), only_path: true)

Return NoMethodError: undefined method `signed_id'

Ben
  • 660
  • 5
  • 25

1 Answers1

0

Rails 6.1 introduced support for public storage. For example:

s3_public:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:s3, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:s3, :secret_access_key) %>
  bucket: bucket_name
  public: true

You can set the storage service on a per-attachment basis in case you don't want everything public:

has_one_attached :pdf, service: :s3_public
idmean
  • 14,540
  • 9
  • 54
  • 83
  • Great, but I'm not on rails 6.1 :( – Ben Jan 22 '21 at 11:30
  • @Ben That's a pity. What version are you on? The best options you have in <6.1 is https://stackoverflow.com/questions/52571555/how-do-you-change-the-active-storage-service-url-expires-in-timeout, which is... not actually a solution. Active Storage is *really* opinionated, maybe ditch it all together. – idmean Jan 22 '21 at 13:16