We've moved discussions to Discord

AWS S3 Error For Displaying Avatars

In my application (using the default JumpStart template), none of the user's avatar images show up. The avatar where the user profile dropdown button is on the navbar always displays a broken image and the same thing happens on the user profile page that I have created.

I have this in my user.rb and account.rb:
has_one_attached :avatar

This is all that appears in my stack trace:

ActiveStorage::Blob Load (0.4ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2  [["id", 5], ["LIMIT", 1]]
00:43:50 web.1     |   S3 Storage (213.6ms) Checked if file exists at key: variants/pxgp5dhqmvn3n7m0118cuaqtfk4n/45860c5eaf11234d1a6c2b398ebbd1ecbd7bca9b35e3562c53958d2d40390dc0 (no)
00:43:50 web.1     | Completed 500 Internal Server Error in 217ms (ActiveRecord: 0.4ms | Allocations: 6610)
00:43:50 web.1     |
00:43:50 web.1     |
00:43:50 web.1     |
00:43:50 web.1     | Aws::S3::Errors::Forbidden - :
00:43:50 web.1     |
00:43:50 web.1     | Started GET "/cable" for 127.0.0.1 at 2020-08-21 00:43:47 -0400
00:43:50 web.1     | Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2020-08-21 00:43:47 -0400


Here is the rest of the stack trace:

00:43:50 web.1     |   Rendered shared/_notifications.html.erb (Duration: 1.9ms | Allocations: 1213)
00:43:50 web.1     |   ActiveStorage::Attachment Load (0.2ms)  SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4  [["record_id", 11], ["record_type", "Account"], ["name", "avatar"], ["LIMIT", 1]]
00:43:50 web.1     |   ↳ app/helpers/accounts_helper.rb:9:in `account_avatar'
00:43:50 web.1     |   ActiveStorage::Attachment Load (0.2ms)  SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4  [["record_id", 5], ["record_type", "User"], ["name", "avatar"], ["LIMIT", 1]]
00:43:50 web.1     |   ↳ app/helpers/application_helper.rb:7:in `avatar_url_for'
00:43:50 web.1     |   ActiveStorage::Blob Load (0.2ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2  [["id", 5], ["LIMIT", 1]]
00:43:50 web.1     |   ↳ app/helpers/application_helper.rb:7:in `avatar_url_for'
00:43:50 web.1     |   Account Load (0.2ms)  SELECT "accounts".* FROM "accounts" INNER JOIN "account_users" ON "accounts"."id" = "account_users"."account_id" WHERE "account_users"."user_id" = $1  [["user_id", 5]]
00:43:50 web.1     |   ↳ app/views/shared/_navbar.html.erb:60
00:43:50 web.1     |   Rendered shared/_navbar.html.erb (Duration: 17.1ms | Allocations: 25877)
00:43:50 web.1     |   Announcement Load (0.2ms)  SELECT "announcements".* FROM "announcements" ORDER BY "announcements"."published_at" DESC LIMIT $1  [["LIMIT", 1]]
00:43:50 web.1     |   ↳ app/helpers/announcements_helper.rb:19:in `unread_announcements_class'
00:43:50 web.1     |   Rendered shared/_footer.html.erb (Duration: 2.1ms | Allocations: 2530)
00:43:50 web.1     | Completed 200 OK in 30ms (Views: 25.6ms | ActiveRecord: 1.2ms | Allocations: 35705)
00:43:50 web.1     |
00:43:50 web.1     |
00:43:50 web.1     | Started GET "/__rack/swfobject.js" for 127.0.0.1 at 2020-08-21 00:43:46 -0400
00:43:50 web.1     | Started GET "/__rack/web_socket.js" for 127.0.0.1 at 2020-08-21 00:43:46 -0400
00:43:50 web.1     | Started GET "/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--062524d2f855495509185b261d57c156d72ed55a/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld2c2RG5Sb2RXMWlibUZwYkVraUN6UTRlRFE0WGdZNkJrVlVPZ3huY21GMmFYUjVTU0lMWTJWdWRHVnlCanNIVkRvTFpYaDBaVzUwU1NJS05EaDRORGdHT3dkVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--80d4b171bdd39eeb85147c1f43358fae7f20045a/avatar_man_brownHair_m2.png" for 127.0.0.1 at 2020-08-21 00:43:47 -0400
00:43:50 web.1     | Processing by ActiveStorage::RepresentationsController#show as PNG
00:43:50 web.1     |   Parameters: {"signed_blob_id"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--062524d2f855495509185b261d57c156d72ed55a", "variation_key"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld2c2RG5Sb2RXMWlibUZwYkVraUN6UTRlRFE0WGdZNkJrVlVPZ3huY21GMmFYUjVTU0lMWTJWdWRHVnlCanNIVkRvTFpYaDBaVzUwU1NJS05EaDRORGdHT3dkVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--80d4b171bdd39eeb85147c1f43358fae7f20045a", "filename"=>"[FILTERED]"}
00:43:50 web.1     |   ActiveStorage::Blob Load (0.4ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2  [["id", 5], ["LIMIT", 1]]
00:43:50 web.1     |   S3 Storage (213.6ms) Checked if file exists at key: variants/pxgp5dhqmvn3n7m0118cuaqtfk4n/45860c5eaf11234d1a6c2b398ebbd1ecbd7bca9b35e3562c53958d2d40390dc0 (no)
00:43:50 web.1     | Completed 500 Internal Server Error in 217ms (ActiveRecord: 0.4ms | Allocations: 6610)
00:43:50 web.1     |
00:43:50 web.1     |
00:43:50 web.1     |
00:43:50 web.1     | Aws::S3::Errors::Forbidden - :
00:43:50 web.1     |
00:43:50 web.1     | Started GET "/cable" for 127.0.0.1 at 2020-08-21 00:43:47 -0400
00:43:50 web.1     | Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2020-08-21 00:43:47 -0400


I thought I set the configuration of the S3 Bucket correctly, but perhaps I missed something? Any help will be greatly appreciated. Thank!
So, I think I've figured out why I keep getting the broken links only for displaying the user's avatar and not the other images.

I've created numerous seed files for my models. All of them attach images to their respective objects (ex. :logo for a Company, :images for a Product), but because JumpStart comes with its own User and Account system, it creates a variant of the avatar and stores it.

However, in my users.rb seed file, I wasn't creating any variants. Therefore, when I start my application and try to display the user's avatar, I get the error I posted above. Now, this line of the error makes much more sense:

00:43:50 web.1     |   S3 Storage (213.6ms) Checked if file exists at key: variants/pxgp5dhqmvn3n7m0118cuaqtfk4n/45860c5eaf11234d1a6c2b398ebbd1ecbd7bca9b35e3562c53958d2d40390dc0 (no)

I kept thinking it was some issue with my S3 permissions configuration, but again, all the other images load fine.

Also, the avatar will display if I use rails_blob_path, like so:
<%= image_tag rails_blob_path(@user_profile.avatar) %>

Is creating a variant in a seed file as simple as calling variant before attach? Does anyone have any experience with this? Also, what are the variants that JumpStart creates so I could mimic that in my seed file?

Thanks :)
Notifications
You’re not receiving notifications from this thread.