Difficulties getting files stored in R2 via https by workers

First of all, I don’t know anything about Cloudflare workers, I only know Javascript.
I’m trying to create a Cloudflare workers to get access to files stored in my R2 using an https request (especially photos) but using the codes provided by the Cloudflare documentation, I’ve only been getting error messages
I’ve already added R2 in the workers’ variables, I’ve tried other codes provided by the documentation, they all have errors, below some of them.


code captured from https://developers.cloudflare.com/r2/examples/demo-worker/

workers settings:

my goal is just to get the files via https call just like on Amazon S3

The example code is TypeScript whereas the Quick Edit that you’re using is for JavaScript.

You need to use wrangler to create that Worker example - take a look at https://developers.cloudflare.com/r2/get-started/

Please note that Worker is a demonstration as well - not for production use, but just to showcase the APIs. It’d allow anyone to send a DELETE request that’ll remove a given file.

I’d recommend using something like GitHub - kotx/render: Cloudflare Worker to proxy and cache requests to R2 if you’re just serving files.

1 Like

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