Rails: Refile gem (attachment_image_tag打印错误的URL)



我使用refile gem进行文件上传,我直接将文件上传到我的amazon s3公共桶。文件上传到以下网址:

https://s3.amazonaws.com/{bucket-name}/store/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475

我使用amazon cloudfront从s3提供这些资产,所以上面给出的资产的cloudfront url是这样的:

https://{distribution-name}.cloudfront.net/store/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475

这两个url在通过浏览器直接访问时工作正常。要在我的应用程序视图文件中显示这个资源,我使用refile gem以下helper函数:

attachment_image_tag(@post, :profile_img, :fill, 350, 350)

现在的问题是,这个助手方法打印的URL是这样的:

https://{distribution-name}.cloudfront.net/attachments/5845d0a97dc77a57b5b05742a1eb26d629d7cdaa/store/fill/350/350/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475/file

由于此URL与上面的cloudfront URL不同,因此不显示图像。如何强制attachment_image_tag函数打印正确的云前端URL?

问题已解决。这个问题是由github上的另一个人指出的:https://github.com/refile/refile/issues/500#issuecomment-239784247

听起来你可能已经设置了Cloudfront发行版你的S3桶作为它的起源?但是,Refile并不生成url直接到S3上的文件(参见README第3节)。架应用程序)。因此,您需要将Cloudfront发行版的origin设置为是应用程序的URL。这样,文件就可以从您的应用程序的第一个请求,并由Cloudfront缓存未来的请求。

最新更新