Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Storage Permanent Image URL

I'm creating a google product listing for a website built in Ruby on Rails. The website has multiple stores with their own front ends so they're wanting a Google Product Feed for each store.

The issue I'm having is if I use url_for(image) then I get the URL for the image on that store. But the way active storage works it's on a temporary URL that lasts 5 minutes by default. So the links wouldn't work on the feed by the it's been processed.

The images are hosted on an S3 bucket so I can get the service_url. But Google doesn't like having the images coming from a separate domain to the store. Is there a way to have a permanent clean url from the stores domain?

like image 619
Tom Avatar asked Dec 20 '18 13:12

Tom


2 Answers

I think what you're after isn't easily possible. Active Storage doesn't seem to support permanent, non-expiring URLs: "Request has expired" when using S3 with Active Storage

Depending on your setup, there might be a useful and (mostly) hack-free workaround. In my case, I've set a custom show action on the record that owns the file I want to link to:

redirect_to url_for(@record_name.file)

Then, using a path helper for the record show action in my app, as usual, just renders the thing I want via the expiring url_for.

like image 104
andrewhaines Avatar answered Sep 21 '22 10:09

andrewhaines


Try rails_blob_url

rails_blob_url(image, disposition: "attachment")

Update: Link updated.

like image 20
mehedi Avatar answered Sep 23 '22 10:09

mehedi