Okay so yesterday I have discovered one cause for the issue.
For saving bandwidth and server resources, I use Optimole with the CDN on when I make copies of my website for local development and staging, then simply change the URL of the meta box (using Velvet Blues Update URLs plugin
) to correctly point the image URL toward my main domain, where the images are stored in the cloud. It goes a bit like this.
- Images get uploaded to the live version of the site.
- I make a copy of my website to my staging and/or local environment using Duplicator Pro.
- Since all instance of “domain.com” URL gets changed to “staging.domain.com”or “localhost/domain”, I use Velvet Blues Update URLs to update all my image URL to point toward “domain.com” instead (because “optimole.cdn/staging.domain.com/image.jpg” or “optimole.cdn/localhost/domain.com/image.jpg” simply doesn’t exist),
- Once I am done with developing my feature, I import all new content my clients might have created on the live site to the staging. This requires me to rollback the images on the live site before using the WordPress Importer to transfer my media files. *
So far so good. However, when using the WordPress importer, things can get tricky. I haven’t followed what happened there 100% but I think it’s because I might have duplicated the import. I think something like this happens.
- Image on live site is marked as such:
optimole.cdn/domain.com/image.jpg
- Image on staging is normally marked as such:
optimole.cdn/staging.domain.com/image.jpg
(I do not disable the CDN since image URL should match anyway). The original image should be simply named image.jpg
- However, the image Optimole picks up is called
image-1.jpg
. This is probably due to the WordPress importer uploading images with the image.jpg
name twice in the same day. This create a cdn link looking like this: optimole.cdn/staging.domain.com/image-1.jpg
- Once I push my staging site to live, it changes the staging URL to the live once, converting
optimole.cdn/staging.domain.com/image-1.jpg
to optimole.cdn/domain.com/image-1.jpg
However, optimole.cdn/domain.com/image-1.jpg
doesn’t exist! only optimole.cdn/domain.com/image.jpg
does, which results in a 400 error when Optimole try to look at optimole.cdn/domain.com/image-1.jpg
in its CDN!
Potential solution: make the local, staging, and live site share the same media pool under the same “domain” in Optimole’s CDN. (Not entirely sure if there is an option for that yet. If so, I haven’t figured it with current documentation.)
* I usually avoid rollbacking my images. The reason being that doing so replace the URL of the image with my local URL (normal) and affect the “last edited” date of my blog posts (undesirable effect) on top of being a lengthy operation. Since the live site will be replaced by what’s in the staging very soon, I don’t care too much about that “last edited” date changes on the live site.
I think there is another case where this 400 error happens where it was truly “random” (no deployment/dev copies installed recently). I’ll let you know when I’ll encounter this again.
Hopefully this helps.
-
This reply was modified 3 years, 9 months ago by
Nazrinn.
-
This reply was modified 3 years, 9 months ago by
Nazrinn.
-
This reply was modified 3 years, 9 months ago by
Nazrinn.