Ask A Question


You’re not receiving notifications from this thread.

How do I get avatar.variant(resize: “200x200”) on Rails 5 to work using aws on production?

Luis Daniel Fonseca asked in General

I can't get user.avatar.variant(resize: "200x200") to work while using a cloud provider in production because it uses my website path instead of aws.

<%= image_tag user.avatar.variant(resize: "200x200") %> 

# Current Output
<img src="">

# Should be
<img src="">

I need to user.avatar.service_url.split("?").first to get the right path for the img but when I do this, I can't use .variant() because that path is a string.

# this works but can't resize    
<%= image_tag user.avatar.service_url.split("?").first %> 

Any idea how I overcome this.



ActiveStorage URLs always go through your Rails app. That's how they generate the resize 200x200 on the fly without precomputing it. That's the primary downside to using ActiveStorage right now.

In a future version of Rails, they will have an option to use direct urls to AWS, but you can't do that right now.

If you want this feature today, you'd be better off using Shrine for file uploads.


Hey Chris! Thanks a lot for getting back to me.

Do you think it would make sense to implement like a post-process user images feature?

Something like this:

While they release that option of using direct urls to AWS on Active Storage.

The thing is that I already implemented the basic features for active storage, and I already had some users uploading their profile picture.

Thanks again!


Yeah, that would probably work fine for now. I'm not sure when Rails 6.1 will come out but it might be a little while so you'll probably need a solution like this until then. This basically replicates what Shrine would do for you.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,453+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.