“请求已过期";将S3与Active Storage一起使用时 [英] "Request has expired" when using S3 with Active Storage
问题描述
我第一次使用ActiveStorage. 在开发过程中一切正常,但在生产中(Heroku),我的图像无故消失了.
I'm using ActiveStorage for the first time. Everything works fine in development but in production (Heroku) my images disappear without a reason.
他们第一次显示正常,但现在没有图像显示.在控制台中,我可以看到此错误:
They were showing ok the first time, but now no image is displayed. In the console I can see this error:
GET https://XXX.s3.amazonaws.com/variants/Q7MZrLyoKKmQFFwMMw9tQhPW/XXX 403 (Forbidden)
如果我尝试直接访问该URL,我会得到一个XML
If I try to visit that URL directly I get an 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
用简单的话来说,我不希望图像过期但要一直存在.
In simple words, I don't want images to expire but to be always there.
谢谢
推荐答案
ActiveStorage不支持未过期的链接.它使用到期链接(私有),并且仅支持在服务上以私有形式上载文件.
ActiveStorage does not support non-expiring link. It uses expiring links (private), and support uploading files only as private on your service.
这对我来说也是一个问题,仅对S3做2个补丁(警告),另一个为has_one_attached和has_many_attached方法添加acl选项的.
It was a problem for me too, and did 2 patches (caution) for S3 only, one simple ~30lines that override ActiveStorage to work only with non-expiring (public) links, and another that add an acl option to has_one_attached and has_many_attached methods.
希望有帮助.
这篇关于“请求已过期";将S3与Active Storage一起使用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!