我是第一次使用 ActiveStorage。
在开发中一切正常,但在生产(Heroku)中,我的图像无缘无故消失了。
他们第一次显示正常,但现在没有显示图像。在控制台中我可以看到这个错误:
GET https://XXX.s3.amazonaws.com/variants/Q7MZrLyoKKmQFFwMMw9tQhPW/XXX 403 (Forbidden)
如果我尝试直接访问该 URL,我会得到一个 XML
<Error>
<Code>AccessDenied</Code>
<Message>Request has expired</Message>
<X-Amz-Expires>300</X-Amz-Expires>
<Expires>2018-07-24T13:48:25Z</Expires>
<ServerTime>2018-07-24T15:25:37Z</ServerTime>
<RequestId>291D41FAC6708334</RequestId>
<HostId>lEVGuwA6Hvlm/i40PeXaje9SEBYks9+uk6DvBs=</HostId>
</Error>
这就是我的观点
<div class="cover" style="background-image: url('<%= rails_representation_path(experience.thumbnail) %>')"></div>
这就是我在模型中所拥有的
def thumbnail
self.cover.variant(resize: "300x300").processed
end
简而言之,我不希望图像过期,而是始终存在。
谢谢
最佳答案
ActiveStorage 不支持非过期链接。它使用过期链接(私有(private)),并支持仅在您的服务上将文件作为私有(private)上传。
这对我来说也是个问题,并且做了 2 补丁 (注意)仅适用于 S3,one simple ~30lines覆盖 ActiveStorage 以仅与未过期(公共(public))链接和 another that add an acl option to has_one_attached and has_many_attached methods 一起使用.
希望能帮助到你。
关于ruby-on-rails - "Request has expired"将 S3 与 Active Storage 一起使用时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51502519/