0
votes

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

2 Answers

1
votes

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

0
votes

The trick is to use service_url to persist images in your applications views.

For example: <%= image_tag(@user.avatar.service_url) %>