首页 > 解决方案 > 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?

标签: ruby-on-railsrails-activestorage

解决方案


我认为你所追求的并不容易。Active Storage 似乎不支持永久的、不会过期的 URL:将 S3 与 Active Storage 一起使用时出现“请求已过期”

根据您的设置,可能会有一个有用且(大部分)免破解的解决方法。就我而言,我在show拥有我要链接到的文件的记录上设置了一个自定义操作:

redirect_to url_for(@record_name.file)

然后,像往常一样,在我的应用程序中使用路径助手进行记录show操作,只是通过 expiring 呈现我想要的东西url_for


推荐阅读