Search code examples
ruby-on-railsrails-activestorage

Rails ActiveStorage - Uploaded image throws error 400 after 5 minutes


So I've heard a lot about Rails 5.2 and ActiveStorage, and there was a lot of talk about ActiveStorage being a drop in replacement for image handling in rails.

My issue is, I've set it up and upgraded my app. I upload an image, it goes to my Google Cloud storage bucket, and that's all fine.

The issue is, In my view I've tried stuff like:

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

and

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

These will show the uploaded image for about 5 minutes, then the vanish from my view. If I inspect, it says error 400. How can I solve this? I want my users avatars to be showing up permanently, not going away.

Please suggest, been searching and reading for hours about how to solve this.

edit: doing "open image in new tab" results in this XML error

<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>

Solution

  • The default expiry of image urls is 5 minutes (https://guides.rubyonrails.org/active_storage_overview.html#linking-to-files)

    You can probably set a new key url_expires_in in your active storage config for google cloud services