Can I host static .json files on Pages? I want to upload them via REST

Hi!

e.g I have a cloud function that runs 1x per day and gets the top 10 news of the day from a source. I now create a .json object with these 10 news, and now instead of uploading it to Google Cloud Storage, I want to upload them to Cloudflare Pages (via REST).

Is that possible?

Would be possible with a custom CF worker, but pages itself only builds from Git for now.

1 Like

thanks buddy! but how with a cf worker?

worker sites ain’t a solution i think… there’s only this wrangler stuff
https://developers.cloudflare.com/workers/platform/sites#:~:text=Workers%20Sites%20enables%20developers%20to,and%20React%20Open%20external%20link.

Workers sites would also work, they just don’t provide a REST api. You could create a rest api with workers that takes in a file via POST and uploads it to a KV namespace, which is later accessible by workers sites or your own KV serving code.

Some example code is here: https://github.com/judge2020/cloudflare-file-hosting/blob/aada69c6a4ddea2df104b18378cc71fd7f7c2964/worker/workerCode.ts#L9

But you will need to look into workers documentation and examples and code the worker if you want this specific rest API. Cf does not provide it natively.

1 Like