Some image sizes returning 302 followed by 404

Hi, thanks for the help with this. Running into something a bit weird with images at multiple sizes that have already been created.

  • What’s your URL?
    • I am limited with how many links I can put as a new user, so the image URLs are linked below, under “Steps to repro the bug/issue”.
  • What version of Ghost are you using? Latest, 5.17.2

And

  • How was Ghost installed and configured? Manually in Ubuntu using ghost install.
  • What Node version, database, OS & browser are you using?
    • Node 16.17.1
    • MySQL 5.7.33
    • Ubuntu 16.04.03 LTS
    • Browser doesn’t seem to matter, tried in Firefox and Chrome latest.
  • What errors or information do you see in the console?
    • Accessing images under w600 results in multiple redirects, which ends up redirecting to a non-sized version of the image, which returns 404.

Steps to repro the bug/issue

This image works: https://blog.teclado.com/content/images/size/w2000/2022/04/christin-hume-mfB1B1s4sMc-unsplash.jpg (the w1000 image works too)
But in this image you can see the redirects happening (in the dev tools) and the resultant 404: https://blog.teclado.com/content/images/size/w600/2022/04/christin-hume-mfB1B1s4sMc-unsplash.jpg

Checking my filesystem, I can see the images are there in both folders:

For width 2000:

ls -al content/images/size/w2000/2022/04
total 436
drwxrwxr-x 2 ghost ghost   4096 Oct  6 10:51 .
drwxrwxr-x 9 ghost ghost   4096 Oct  6 10:51 ..
-rw-rw-r-- 1 ghost ghost 224084 Oct  6 10:52 christin-hume-mfB1B1s4sMc-unsplash.jpg
-rw-rw-r-- 1 ghost ghost 209068 Oct  6 10:52 christopher-gower-m_HRfLhgABo-unsplash.jpg

For width 600:

ls -al content/images/size/w600/2022/04
total 72
drwxrwxr-x 2 ghost ghost  4096 Oct  6 10:51 .
drwxrwxr-x 9 ghost ghost  4096 Oct  6 10:51 ..
-rw-rw-r-- 1 ghost ghost 30727 Oct  6 10:52 christin-hume-mfB1B1s4sMc-unsplash.jpg
-rw-rw-r-- 1 ghost ghost 30916 Oct  6 10:52 christopher-gower-m_HRfLhgABo-unsplash.jpg

Above these directories I’ve already checked that the owner is correct, everything is under ghost:ghost:

ls -al
total 64
drwxr-xr-x   6 jose  jose   4096 Oct  7 08:09 .
drwxr-xr-x   6 root  root   4096 Sep 29 13:00 ..
-rw-rw-r--   1 jose  jose    201 Oct  7 08:09 .ghost-cli
-rw-rw-r--   1 jose  jose   1400 Oct  7 08:28 config.production.json
drwxrwxr-x  12 ghost ghost  4096 Oct  6 13:05 content
lrwxrwxrwx   1 jose  jose     34 Oct  7 08:09 current -> /var/www/ghost-new/versions/5.17.2
drwxrwxr-x 122 jose  jose   4096 Oct  6 13:06 node_modules
-rw-rw-r--   1 jose  jose     69 Oct  6 13:04 package.json
drwxrwxr-x   3 jose  jose   4096 Sep 29 13:03 system
drwxrwxr-x   4 jose  jose   4096 Oct  7 08:08 versions
-rw-rw-r--   1 jose  jose  25517 Oct  6 13:04 yarn.lock
ls -al content/images
total 36
drwxrwxr-x  9 ghost ghost 4096 Oct  6 10:52 .
drwxrwxr-x 12 ghost ghost 4096 Oct  6 13:05 ..
drwxrwxr-x  6 ghost ghost 4096 Dec  6  2017 2017
drwxrwxr-x  8 ghost ghost 4096 Nov 14  2018 2018
drwxrwxr-x 13 ghost ghost 4096 Dec  5  2019 2019
drwxrwxr-x  6 ghost ghost 4096 Oct  6 10:52 2020
drwxrwxr-x  8 ghost ghost 4096 Oct  6 10:52 2021
drwxrwxr-x 10 ghost ghost 4096 Oct  6 13:11 2022
drwxrwxr-x  7 ghost ghost 4096 Sep 29 13:13 size
ls -al content/images/size
total 28
drwxrwxr-x 7 ghost ghost 4096 Sep 29 13:13 .
drwxrwxr-x 9 ghost ghost 4096 Oct  6 10:52 ..
drwxrwxr-x 7 ghost ghost 4096 Oct  6 10:51 w100
drwxrwxr-x 7 ghost ghost 4096 Oct  6 10:51 w1000
drwxrwxr-x 7 ghost ghost 4096 Oct  6 10:51 w2000
drwxrwxr-x 3 ghost ghost 4096 Sep 29 13:13 w256h256
drwxrwxr-x 7 ghost ghost 4096 Oct  6 10:51 w600
ls -al content/images/size/w2000
total 28
drwxrwxr-x  7 ghost ghost 4096 Oct  6 10:51 .
drwxrwxr-x  7 ghost ghost 4096 Sep 29 13:13 ..
drwxrwxr-x  6 ghost ghost 4096 Oct  4 16:37 2018
drwxrwxr-x 13 ghost ghost 4096 Oct  4 14:04 2019
drwxrwxr-x  6 ghost ghost 4096 Oct  6 10:51 2020
drwxrwxr-x  8 ghost ghost 4096 Oct  6 10:51 2021
drwxrwxr-x  9 ghost ghost 4096 Oct  6 10:51 2022

Anyway I checked them all, it’s all ghost:ghost.

Deviation from the standard install

In my config.production.json I’ve got this:

"imageOptimization": {
  "resize": false
}

Because I’m using the ghost-storage-cloudinary storage adapter (which does seem to work on new image uploads). However, as far as I can see in the documentation, setting resize: false only affects image upload to Ghost, and not image serving. The images under w2000 and w600 (and others) were uploaded to Ghost before I started using the cloudinary storage adapter.

FWIW, this is my theme’s code for the image:

<img class="post-card-image"
    srcset="{{img_url feature_image size="m"}} 600w,
            {{img_url feature_image size="l"}} 1000w,
            {{img_url feature_image size="xl"}} 2000w"
    sizes="(max-width: 1000px) 400px, 700px"
    src="{{img_url feature_image size="m"}}"
    alt="{{title}}"
/>

Could you give me a hand with this issue?

  • I would expect the image at w600 to be served (especially since it’s there in the filesystem!).
  • Failing that, I would expect the base image not to return 404, since it’s also there in the path /content/images/2022/04/christin-hume-mfb1b1s4smc-unsplash.jpg

Thank you!

Jose

Bump! Any ideas on what could be going wrong?
Thank you!

After much investigation, it seems the problem is caused by the storage adapter: GitHub - eexit/ghost-storage-cloudinary: A fully-featured and deeply tested Cloudinary Ghost storage adapter

When an image that already exists in the filesystem but not in Cloudinary is requested, it doesn’t fall back to the filesystem and causes this weird 301 → 404 redirection.

I’ve raised an issue with them: Images uploaded before activating this adapter return 404 · Issue #152 · eexit/ghost-storage-cloudinary · GitHub