Cloudflare Images & Wordpress

Hello guys,

I’m looking for a way to programmatically upload the Wordpress Media files to Cloudflare’s Images CDN.
To be specific, I’m talking about the paid service for storing/resizing images from Cloudflare.
I’ve read the docs provided here but that’s not very helpful.

Manually uploading images to Cloudflare Images is not an option for me. And the curl API option is very user friendly and not programatic either.

I’ve searched the web for WP plugin, but haven’t managed to find one.
At this point I could be content even with a custom php script, maybe combined with a cron job ?!

If no option is available, I’ll probably cancel the subscription to CF Images, which would be pity, cause I was looking forward to using the resizing images feature.

Thanks all and have a nice day

Reminds me on a recent topic:

I am sorry to hear that.

It can be done using Postman, Cloudflare Workers, or even via PHP as a HTTP request. You can send cURL request using PHP either via Procedural or an Object oriented way, if you are familiar with that maybe?

If so, if familiar with PHP and WordPress, by the WordPress documentation and my knowledge of the plugin/theme development, even translation of the WordPress core, internally, WordPress uses the WP_Http class for network requests, which in turn relies on the Requests library so far.

Meaning, all of the HTTP utility methods like wp_remote_get() and wp_remote_post() use Requests. At a high level, WordPress updates, plugin downloads, plugin updates, and pretty much any upload/download functionality in WordPress core are using the Requests abstraction of the cURL bindings and options.

Nevertheless, you can attach an function to the event (like wp_handle_upload()) that does it using add_action() and execute curl_exec() (or actually the wp_remote_post() as it’s the POST request in the Cloudflare Developer’s documentation for Cloudflare Image upload) within it into from your functions.php.

Just an idea, as far as I think it should work like that for issuing HTTP requests.

If interested, I could help with that (we need a Web server like Nginx, OpenSSL, PHP with a cURL support, WordPress installed and Cloudflare Images) :slight_smile:

I am afraid WP plugin does not yet exist, at least I haven’t come a cross one yet.

Even I would not actually recommend a plugin to directly execute cURL due to some issues like event handlers could hang within the cURL request/response, security, etc.

Somehow, reminds me to plugins of WordPress “offload media” to some external CDN storage (works okay, but …):

Hopefully, you would only have images (as a extension and a MIME-Type) on the upload process to your WordPress Media Library (Cloudflare Images for further resizing, etc.), right?


Hi fritexvz, thanks for taking your time with the reply

Yes, I’ve read that topic beforehand, but still I thought it’s worth trying with a new topic.

My team constantly adds new content on the website, that’s why manually uploading the images isn’t an option, as I wouldn’t be able to keep up with the new content.

Well, having created custom themes and plugins from scratch, I’d say I have good experience with WP. Also, I’m not a big fan of using third party plugins, I prefer to make my own for whatever needs my project has. In this case however, due to time and resources limitations, I was looking for a fast plug-n-play option.
Still, I haven’t thought of your idea before posting this topic… haven’t used the WP_Http class before either.

I agree, thought of something like that too, but it’s not the best…

Yes, only images.

Thanks for the offer, I’ll keep this in mind, but for now I’m thinking of a different approach, one that doesn’t involve CF Images anymore.
I’ve researched some more about the specs of CF Images and the resizing service and it seems that for the customisation level needed, I’d have to get the Enterprise package, which is too expensive for our budget at the moment.

Long story short, what I’m trying to achieve is delivering images resized to the actual rendering size (for each device/browser resolution possible).
The logic is to calculate the image’s rendered size (client side), before the image is actually requested & loaded by the browser. Afterwards, apply that calculated value as GET argument to the image url (alongside other params, such as quality and WebP) and let the browser request said image.
This way I can guarantee maximum optimisation of the image, on every possible device / browser resolution.

However, another factor in all this scheme, is optimising the cost. Our business is projected to have a lot of traffic in the near future, so this has shortened my list of options.

The alternative that I now have in mind, is using the CDN, strictly for storing and resizing the images on the fly.

Regarding CF, having used for the first time (in years) a paid package from CF (the Pro), I still like the new options available, so I’ll keep it.

Again, thanks for the reply and have a nice day

1 Like

This topic was automatically closed after 15 days. New replies are no longer allowed.