Is it possible for the API to check the image and add it to Cache/CDN?

Hi! I’m using google translator so I ask for a little patience if something is not clear, I’m available to explain more if you need it <3

I searched the forums in my native language and in English and I couldn’t find something similar to my case in the searches (if you find a similar topic, I’d really appreciate it)

I’m starting in programming and I have an idea that I believe Cloudflare can solve, as I’m new, I was a little lost in the documentation without knowing if it’s what I really need

My idea is for my website to work like this:
Frontend requests an image → Api/Backend takes this request with the image route, checks if it is in cache/cdn on Cloudflare, if yes, returns the image link, if not, takes this image from S3 or VPS Disk , sends to the CF cache/cdn at the maximum possible storage time limit (days or months?) and returns the new link of the cached image/cdn for the frontend
I only found courses/ways to cache/cdn full links like example.com/example
or example.com/example/3
But I want to call the page exemple.com/example from the frontend and the links of the images inside it to be in Cloudflare

It is possible? If so, I would really appreciate it if you could light my way by pointing me to a piece of documentation that talks about it (I couldn’t find it :frowning:
If not, thank you for reading this far.

Hello there!

This is how Cloudflare (or any other CDN, for that matter, with some small caveats depending on implementation) works already.

If you have your domain proxied with Cloudflare all resources will get cached according to either the headers or rules you specify. Do note that time to cache the resource is always up to the number you select, as it can evicted from cache for any number of reasons (too low request counts, big files, hardware issues, etc.). You will need to expect some files being requested multiple times per location (and each location will request each file the first time it’s accessed through it).

If you want something more to read about, here is a decently good resource. Don’t esitate to ask if you have additional questions.

https://www.cloudflare.com/learning/

Hey Matteo, thanks for the reply!
So, this part I understood about Cloudflare doing the work “automatically”, my idea would be to do this process, let’s say, more “manually”, that is, instead of letting Cloudflare handle it automatically, I would have, for example, some kind of passkey where my api could, for example, upload whatever image I want whenever I want (assuming this is possible on the paid plan)
That is, if a user accesses an image, it will be sent to the CDN/Cache
So instead of the image being returned from the location:
example.com/page -> a image link like -> example.com/image-3.jpg (local/S3)
It would return from:
example.com/page -> a image link like -> cdn.example.cloudflare.com/image-3.jpg for my frontend
Does the automatic form of CF already do this? Because the idea would be to leave it in cache to save on S3 requests
But I’m reading through the link you gave me and I’m going to test it here, thanks

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