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 https://developers.cloudflare.com/images/upload-images 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.
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.
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 statically.io 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.