# Can't generate user avatars when moving to new server because extension is "unknown"

**URL:** https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134
**Category:** Bug
**Created:** [October 26, 2021, 2:35pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134 "2021-10-26T14:35:36Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 26, 2021, 2:35pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/1 "2021-10-26T14:35:36Z")

</div>

EDIT: I’m reclassifying this as a bug, so that someone who understands this better than I can take a look at it.

a bunch of uploads had “unknown” as the extension. This means that it’s impossible to generate thumbnails. I think this happened when moving a backup to a new site and then needed to regenerate the thumbnails.

I think what should happen when you try to generate thumbnails and the extension is ‘unknown’ is to replace the extension, something like

```
 upload.extension = upload.original_filename.split('.').last

```

It seems like if this were done somewhere that I’d not have spent 4 hours on this.

Wait. This looks like the problem. Why return `false` rather than get the extension from the filename?

> <https://github.com/discourse/discourse/blob/main/app/models/upload.rb#L151>

## Gory details follow.

I moved a site from `/community` to `community.example.com` by doing a backup and restore. I fixed the uploads with a

```
 RAILS_ENV=production bundle exec script/discourse remap '/community/uploads' '/uploads'

```

But the avatars are still the Gray Man.

When I look at `user.user_avatar.custom_upload.url` and paste that URL into the browser, I get the desired avatar. It seems like I need to “rebake” the users.

I thought that perhaps a

```
rake avatars:refresh

```

or

```
rake avatars:clean 

```

might fix it, but no joy.

What am I missing?

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [October 26, 2021, 2:41pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/2 "2021-10-26T14:41:05Z")

</div>

In sidekiq there is a trigger to create missing avatars.

It takes a while, but that should help if I am not mistaken

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 26, 2021, 2:49pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/3 "2021-10-26T14:49:39Z")

</div>

Good one! That callls `User.refresh_avatar`, but sadly

```
  user=User.find_by_username('broken_avatar_guy')
  user.refresh_avatar

```

also isn’t solving this.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 27, 2021, 12:30pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/4 "2021-10-27T12:30:24Z")

</div>

Here’s a clue:

```plaintext
ActionController::RoutingError (No route matches [GET] "/user_avatar/community.example.com/broken_user")

```

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [October 27, 2021, 12:51pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/5 "2021-10-27T12:51:59Z")

</div>

Do it update when the user logs into their account ?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 27, 2021, 12:54pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/6 "2021-10-27T12:54:40Z")

</div>

I don’t believe so.

`user.user_avatar.custom_upload` has the correct URL, but `https://community.example.com/user_avatar/community.example.com/bad_user/25/321_2.png` has the missing avatgar image. I need to find the way to rebuild those avatar thumbnails.

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [October 27, 2021, 12:56pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/7 "2021-10-27T12:56:26Z")

</div>

there is a force\_avatar\_update in the user login that i saw in the code.

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [October 27, 2021, 1:01pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/8 "2021-10-27T13:01:44Z")

</div>

this could be very helpful, it looks like a job

> <https://github.com/discourse/discourse/blob/1472e47aae5bfdfb6fd9abfe89beb186c751f514/spec/jobs/fix_out_of_sync_user_uploaded_avatar_spec.rb>

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 27, 2021, 6:25pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/9 "2021-10-27T18:25:36Z")

</div>

Something must be wrong:

```plaintext
user=User.find_by_username('Tuomo')
upload_id=user.user_avatar.custom_upload.id
upload = Upload.find(upload_id)
      Discourse.avatar_sizes.each do |size|
        OptimizedImage.create_for(upload, size, size)
      end
OptimizedImage.where(upload_id: upload_id)

```

ANd I get the no opimized images.

```plaintext
broken_uploads = Upload.where(extension: "unknown")
broken_uploads.each do |upload|
  upload.extension = upload.original_filename.split('.').last
  upload.save
end

```

fixes that.

Then I just need to generate new thumbnails, like this:

```plaintext

has_upload = UserAvatar.where("custom_upload_id > 0")

has_upload.each do |user_avatar|
  Jobs.enqueue(:create_avatar_thumbnails,{upload_id: user_avatar.custom_upload_id})
end

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 10, 2021, 8:00pm UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/10 "2021-11-10T20:00:41Z")

</div>

I think that this is a legit bug and Jeff ❤ed, but it hasn’t gotten any more attention.

Am I crazy or is there something broken here?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 14, 2021, 5:37am UTC](https://meta.discourse.org/t/cant-generate-user-avatars-when-moving-to-new-server-because-extension-is-unknown/207134/11 "2021-11-14T05:37:25Z")

</div>

> I moved a site from `/community` to `community.example.com` by doing a backup and restore

I guess we just haven’t run into this with any of our restores, because what you’re complaining about here are restore artifacts, yes? Perhaps specific to this backup and restore?
