Rails ActiveStorage - 上传的图像在 5 分钟后抛出错误 400

Rails ActiveStorage - Uploaded image throws error 400 after 5 minutes

所以我听到了很多关于 Rails 5.2 和 ActiveStorage 的消息,并且有很多人谈论 ActiveStorage 是 rails 中图像处理的替代品。

我的问题是,我已经设置并升级了我的应用程序。我上传了一张图片,它进入了我的 Google 云存储桶,这一切都很好。

问题是,在我看来,我尝试过类似的东西:

   <%= image_tag((current_user.avatar), size: "100x100") %>

<%= image_tag(rails_blob_path(current_user.avatar, disposition: "attachment"), size: "100x100") %>

这些将显示上传的图像大约 5 分钟,然后从我的视野中消失。如果我检查,它说错误 400。我该如何解决这个问题? 我希望我的用户头像永久显示,而不是消失。

请提出建议,已搜索和阅读数小时以了解如何解决此问题。

编辑:"open image in new tab" 导致此 XML 错误

<Error>
<Code>ExpiredToken</Code>
<Message>The provided token has expired.</Message>
<Details>
Request signature expired at: 2018-10-09T20:50:09+00:00
</Details>
</Error>

诀窍是使用 service_url 在您的应用程序视图中保留图像。

例如:<%= image_tag(@user.avatar.service_url) %>

图片网址的默认有效期为 5 分钟 (https://guides.rubyonrails.org/active_storage_overview.html#linking-to-files)

您可以在 google 云服务

的活动存储配置中设置一个新密钥 url_expires_in