Problems with avatar uploads due to S3 changes

Hi everyone,

Somehow I keep having issues with avatars. I’m on the last version (v2.2.0.beta3 +3).

This is something noticed a few weeks ago but I’m only having the time to debug now. At first, I thought it could be a problem with the customizations I did through my theme plugin, but I don’t think that’s the case.

Some images show up but some others don’t. Has anyone seem something like that?

Here’s an example of an image that should be showing up (both urls seem correct):

And here’s another one that works:

Here are all my S3 settings:

1 Like

I think the problem might be related to Gravatar. I’m checking the database and looks like the users where the images are not showing up are the ones that Discourse is trying to download from Gravatar (with no success).

[31] pry(main)> u.user_avatar.update_gravatar!
=> nil
[32] pry(main)> u.refresh_avatar
=> nil
[33] pry(main)> u.user_avatar
=> #<UserAvatar:0x000055e10932f038
 id: 306,
 user_id: 303,
 custom_upload_id: 655,
 gravatar_upload_id: 1282,
 last_gravatar_download_attempt: Fri, 12 Oct 2018 20:08:17 UTC +00:00,
 created_at: Wed, 01 Nov 2017 20:19:44 UTC +00:00,
 updated_at: Mon, 03 Sep 2018 07:30:36 UTC +00:00>
[34] pry(main)> u.small_avatar_url
=> ""
[35] pry(main)> u.refresh_avatar
=> nil
[36] pry(main)> 

And I can confirm that the Gravatar file exists in the S3 bucket by checking the associated object and searching the listed file on Amazon:

[38] pry(main)> u.user_avatar.gravatar_upload

I’m also noticing a really long delay to render some of the images that display correctly.


It is already the weekend for him but @tgxworld can check when it is his Monday

Thank you Jeff! No rush at all. I’m running the rake tasks to refresh the avatars now, and will keep this post updated :slight_smile:

1 Like

Running the rake tasks had no results. I will try to debug more tomorrow.


Can you be sure to update to latest, I did notice some issues with one of our once off jobs did play up on meta FIX: reduce amount of work onceoff does · discourse/discourse@8d06731 · GitHub


Does Upload.find(1282) return an upload record?

Thanks for replying. Yes, it does and the file exists in the bucket too.

[1] pry(main)> Upload.find(1282)
=> #<Upload:0x00005627d96730e8
 id: 1282,
 user_id: 303,
 original_filename: "gravatar.png",
 filesize: 201626,
 width: 360,
 height: 360,
 url: "//",
 created_at: Mon, 03 Sep 2018 07:30:35 UTC +00:00,
 updated_at: Mon, 03 Sep 2018 07:30:36 UTC +00:00,
 sha1: "bdbc5de045297d6279f41cafe5486799823c526b",
 origin: "",
 retain_hours: nil,
 extension: "png",
 thumbnail_width: 360,
 thumbnail_height: 360>

@sam updating from Beta to Stable now and I’ll post back here in a bit. Should I run the rake tasks to refresh everything again?

Interesting, what about upload.optimized_images?

That returns an empty array:

[3] pry(main)> upload.optimized_images
=> []
[4] pry(main)>

Hmm that is the problem here. I’ll have a look at this tomorrow to see if I can reproduce with the given image.

1 Like

Thank you so much! I’m now updating to get Sam’s commit and will run the rake tasks to refresh again, and see what happens.

The problem seems to be widespread actually. Now I’m on tests-passed branch, and I ran both refresh and clean rake tasks, but no luck. The weird thing is that I’m also noticing the same issue with some users that have custom_uploads as well. The ones with custom uploads have optimized_images, but deleting them has no effect either.

I also noticed that the reference that discourse has for the file is not the same URL that I can get from the bucket itself. For example, this the link I get from S3 directly (using their UI):

But this is what I get from the Discourse’s database:


But that’s not the S3 endpoint I have set on my settings page (I have the default). I just changed my s3 endpoint to but no luck either.

If you think having some Gravatar images might help, here’s a list of the one that I noticed the issue:;d=404
1 Like

Did you happen to reconfigure SiteSetting.s3_region recently? It looks like that site setting has been configured to be us-east-1 when it should be us-west-2. works while doesn’t.


Yeah, I had to change after one of the last updates (I explained what happened here Avatar upload failing)

I’m gonna write a rake task to update all the images. I wasn’t sure if changing the region could have affected it since it always worked before the other thread.

I will post my gist with my script to update the images in a bit to maybe help others in the future.

Thanks a lot!

Does that mean the region was incorrectly set initially before it was corrected? You can remap the URLs with bundle exec script/discourse remap // // Please take a backup before running that in case it doesn’t remap correctly.

Awesome, will run the script now. I don’t understand what happened. I never touched the bucket settings on Discourse and my bucket was always west. For some reason it worked before. What I’m noticing is that images stored under 1x don’t use the dualstack url format and all my old uploads are 1x. Don’t know if something changed in the code recently that could have affected that.

Here’s an example:


All the 1X urls work independent of the region but the 2X ones have the region on the url.

Does OnceoffLog.where(job_name: "CorrectMissingDualstackUrls") return anything for you?

I just ran Remap, but checking OnceOfflLog shows this:

[#<OnceoffLog:0x00005639fcad5e58 id: 25, job_name: "CorrectMissingDualstackUrls", created_at: Fri, 07 Sep 2018 18:05:52 UTC +00:00, updated_at: Fri, 07 Sep 2018 18:05:52 UTC +00:00>]

Running Remap and the rake tasks to refresh and clean the avatars solved the problem.

Thank you so much for all the help!!