Broken Images and Their S3 URLs

After the recent update to 2.5.0.beta7 all my images on the forum are broken.

The avatar is also replaced by default one. These are my suggestions on the dashboard:

My Staff Posts for Assets:

One such image: /original/2X/4/4064b1cc32199de63ad2fa2b5bd2a0c5b6872c6d.png

However, my S3 has no such image: (why did this happen?)

My favicon and other logos are missing: /original/1X/b32666bfe0e0eac40aacb178c7430c9f7873b397.png

However, my S3 has these files only:

Notice how the URL is wrong and there is no 1X folder inside the original folder.

I tried following the tutorial of this post:

But it did not fix anything.

may I point out that this image is not in your bucket, it’s 4061…41.png ? :thinking:
Is it present locally ?

I’m sorry, wrong choice of words. I meant to say I noticed it isn’t in the S3 bucket, none of them are.

How do I check for it locally?

Oh, makes indeed more sense :sweat_smile:
You could check locally with any ssh client that you like, depending on your setup, the files should be in something like /var/discourse/shared/standalone/uploads/default/original/2X/
so you might ls -R /var/discourse/shared/standalone/uploads/ | grep 4064b to find the 4064b…d.png

2 Likes

Talking about the same Discourse instance as @masterakay here.

We switched over to s3 over 2 years ago, none of the files in the local uploads directory are newer than 2018.

As I understand, images are uploaded in the “original” folder, and processed (cropped, reduced in size, etc.) and put in the “optimized” folder. The URLs used by discourse when uploading images are still from the “/original/1X/” folder. Somehow, with the upgrade, the “1X” folder is gone.

There’s a “default” folder which as a lot of uploads (images, etc.) as well as cropped versions. There are about 10k files here making it ~2.5 GB.

The problem is the image URL in the posts always have the “original” one.
Something we noticed is that the missing files are a subset of the files in the “default” folder.
New uploads work without issues and are stored in “/original/2X/”.

Does anyone have ideas where the “/original/1X/” folder may have gone and if it possible to bring it back?

2 Likes

@sam @codinghorror I’m so sorry to drag you into this, but it’s quite urgent. We’re students and sort of helpless with the college mounting pressure on us to fix the images.

I’m seeing this as well, and it just started after a more recent update.

1 Like

How do you have S3 setup? Did you set any values in app.yml or just in the admin UI? It looks like something is unexpected for DISCOURSE_S3_BUCKET or DISCOURSE_S3_BACKUP_BUCKET.

4 Likes

Yes, like I explained, everything was fine until the recent update. We have followed all the steps.
In particular, we did something like this:

As for these values, I can’t seem to find any variable set in app.yml. It wasn’t previously required. Did something change?

Indeed. Something may not be working right in the code, but we don’t know what nor why. So we need more information.

There are two different ways to setup S3: You can configure the environment in app.yml or you can enter the values in the admin UI. The variables are named slightly differently in each.

The topic you linked to describes how to setup in the admin UI. If that is how you setup your site, can you tell us what you have for s3_upload_bucket, and s3_backup_bucket?

2 Likes

@schleifer Same for me. I haven’t changed anything in those settings, either. I also verified my AWS credentials are working.

Oh, that explains it.

The problem happened because those settings are not supposed to be the same value – search the setup topic for the line “Do I really need to use separate buckets for uploads and backups?”
A maintenance job ran on the contents of the backup bucket and affected the uploads because their values overlapped.

@sam we should probably enforce that in code, not just documentation

To fix up your site, there’s two steps:

First, you’ll need to change the backups prefix – adding /backups to the end as described in the setup topic, is sufficient.

After, move everything in the S3 bucket back into the correct place. Everything in the top “default” folder should get put back at the top level.
E.g. there’s probably “default/originals” folder there which should be moved up.

You’ll have to use the AWS web console or some other tool to browse the bucket.

5 Likes

Alright, thank you so much! I shall try the steps out and come back here in case anything ever happens. Any idea why this happened all of a sudden? :sweat_smile:

Hey @schleifer that makes sense and added the backups prefix to the bucket name.

As for the existing uploads, all the uploads are in /default/ (not in sub-folders). The image urls in posts (and everywhere else) use /original/* or /optimized/*.

If we move everything in the default folder up one level (to the root), then the images will be in /*.
And no, there aren’t any folders within defaults, just upload files. It seems to contain files with standard 40-char hash filename as well as some with suffixes like “_2_10x10” (which I presume are from optimized).

How do you suggest fixing this? Fixing all posts with new links will take time. Is it possible to somehow group the files in the correct folders based on this filename?

1 Like

@schleifer any updates on this?

That’s…unexpected. We’ll have to fix up a bunch of stuff by hand, then.

The most important question would be “are new uploads going to the correct location?”

Assuming that’s true, you can put the old uploads in a known location and adjust their database entry. How many files are there in /default/?

3 Likes

The new uploads are working as expected into sub-folders, fortunately. And the links in posts point to the correct location.

There are >10k files in /default/. Editing each post manually seems like a lot of work. Is there any way to script this? Maybe with a regex replace on all posts?

That’s the plan, yes. The next thing to do is put all the AWOL files in a known location. In the bucket, what sub-directories are there under /original/? There should be /1X/ and there may be others.

3 Likes

This is the complete folder structure. New uploads (works fine) are stored in /original/2X/*/.jpg

/
|---backups
    |---default
        |---(bunch if backups .tar.gz files)
|---default
    |---(10719 uploaded files pdf, images, etc.)
|---inventory
    |---1/pesuioforum/{optimized,original}/[DATE]/manifest.{checksum,json}
|---optimized
    |---1X
        |---(2 files)
    |---2X
        |---{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f}
            |---(uploaded files that start with the folder's name char above) (1055 files in total)
|---original
    |---2X
        |---(Same as optimized/2X, 520 files)
|---tombstone
    |---optimized
        |---1X
            |---(2 files)
    |---original
        |---2X
            |---(Same as optimized/2X, 1 file)

The next thing to do is put all the AWOL files in a known location.

The /default/ already seems to have all the images.

1 Like