Cloudflare Image Resizing Enabled in the site Speed Optimizing.
Worker setup to use Image Resizing. It validates the request and sets the dimensions.
Custom domain set on R2 to allow public access. The worker uses this domain to access the images in R2 for Image Resizing.
However, this does not work consistently.
When accessing image through the Worker URL, Cloudflare returns the error “ERROR 9421: Too many redirects”.
Eg.
Visit link to view thumbnail: https://<myworker-domain>/<somekeypath>/thumb/IMG_5.jpg.
Wrangler tail shows the worker getting to the end and forwarding the request to Cloudflare Image Resizer.
Error is returned.
Headers show cf-resized: err=9421 , cf-cache-status: BYPASS
Status: 400
Body: ERROR 9421: Too many redirects
If I visit the original image directly I get a constant stream of 301.
Eg.
Visit link to view original image in R2 using custom public domain: https://<r2-custom-public-domain>/<somekethpath>/IMG_5.jpg
Browser returns Status Code 301
Header shows the location header set to the exact same path as in step 1.
This repeats until chrome shows the error ERR_TOO_MANY_REDIRECTS.
I do see the header shows cf-cache-status: HIT
If I purge cache, then refresh the R2 link, I can view the image. Then accessing from the worker works as well, showing the proper thumbnail. However, If I first access the worker link, then I still get the same error as above.
I’ve had a ticket open with Cloudflare support since March 30th and have heard nothing back from their support team.
Using Image Resizing for images stored in R2, subdomain configured to serve images from the bucket.
Just with using the /cdn-cgi/image/Image Resizing prefix, I’m getting the same behavior:
Opening https://cdn-staging.example.com/cdn-cgi/image/w=256/menu/image.jpeg first results in ERROR 9421: Too many redirects.
Any subsequent requests to https://cdn-staging.example.com/menu/image.jpeg (the R2 origin’s public domain) result in redirect loop.
When I purge everything and hit the https://cdn-staging.example.com/menu/image.jpeg first, then I get the image, and all subsequent requests to https://cdn-staging.example.com/cdn-cgi/image/w=256/menu/image.jpeg keep working.
@keith25 did you get any response from the support team? Did you find a workaround?
I had to change the SSL settings for the site to “Full”. I had them set to “Flexible”.
Even though traffic was being sent via HTTPS, this change made things work.
They said this was because:
R2 does not like non HTTPS traffic.
R2 was intended to perform and work only via HTTPS traffic, and as such, the error messaging/execution is not very well documented displayed/relayed.