10

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?

Tom
  • 173
  • 1
  • 8

3 Answers3

5

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.

andrewhaines
  • 186
  • 6
2

Try rails_blob_url

rails_blob_url(image, disposition: "attachment")

Update: Link updated.

mehedi
  • 466
  • 3
  • 8
1

You can get the full URL of an Active Storage attachment using the following:

polymorphic_url(@article.image.variant(resize: '800x600'))

This will provide a full url and not just the path and works well on Rails 5.2+

pastullo
  • 4,171
  • 3
  • 30
  • 36