Home>

Currently, when I set to upload images to S3 using Active Storage in the production environment, the images are not displayed properly and I am in trouble.
However, the image is not displayed, but the image can be posted.
Since I can post images, I thought that there was no problem with the access key and secret key settings, and when I checked the console, the following error occurred. Also, in IAM User, I set a User who has administrator privileges.
Thanks for your understanding.

Path 500 under GET
https://xxxxxx.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--7c84fe0e4db0d5f145bfb6794cf7c30d6f3744a9/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9UY21WemFYcGxYM1J2WDJacGJHeGJCMmxCYVVFPSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--0ae0535ffe18e342a50208e47825434ab16f3deb/dog-5723334_640.jpg
Corresponding source code

_profile_avatar.html.erb

<% if current_user.profile&&current_user.profile.avatar.attached?%>
<% = image_tag current_user.profile.avatar.variant (resize_to_fill: [a, b])%>
<% else%>
<% = image_tag'xxxx.jpg'%>
<% end%>
What I tried

-First, I tried changing the S3 bucket policy settings, but I noticed that it was not relevant because it was accessed by a user with administrator privileges. Also, since I was able to post the image to s3, I thought that there was no problem with the settings there.

-I found that the path generated by image_tag is not the path to S3, so I tried image_tag ulr_for (...), but it didn't work.

<% if current_user.profile&&current_user.profile.avatar.attached?%>
<% = image_tag url_for (current_user.profile.avatar.variant (resize_to_fill: [a, b]))%>
<% else%>
<% = image_tag'xxxx.jpg'%>
<% end%>

Is it difficult to set up S3 in a production environment? Is it just missing something more basic?

https://gyazo.com/c850fdc193f3026ac4937c14a206d8c1

  • Answer # 1

    It was due to S3 settings and linux2 not having ImageMagick!

Related articles