Search code examples
amazon-web-servicesamazon-s3rails-activestorage

Active Storage and S3


I set up Active Storage to use Amazon AWS S3. I have it all set up. When I upload an image it shows up in my AWS bucket just fine. The problem I am having is that when I display the image via <img src="<%= url_for(current_user.avatar) %>"> I get a broken image link.

Now what I get in inspect on the page is: <img src="/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--15a99e4747fa8cdc7cd4bacf3de460d6ce4066de/AlanAlda.png">

but what I get in the rails console is: Redirected to https://hpotter.s3.amazonaws.com/kf3kzqzj54am38jjd7k3jfux4q3d?response-content-disposition=inline%3B%20filename%3D%22AlanAlda.png%22%3B%20filename%2A%3DUTF-8%27%27AlanAlda.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAQQXYWGXDLPMYBQGW%2F20191130%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20191130T011149Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=4c8fff1e88e6b9647d40f73e499edba2078f7a6d9f9c2fb0870477f2a62e9bc7 Completed 302 Found in 141ms (ActiveRecord: 0.9ms | Allocations: 182103) So It's connecting to the right image link but it's the link is different in the actual web browser.

Any ideas?


Solution

  • The value '/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--15a99e4747fa8cdc7cd4bacf3de460d6ce4066de/AlanAlda.png"' is Base64 encoded.

    Did you setup cors correctly https://github.com/rails/rails/issues/30723