Trying to create a worker that fetches the size of my R2 bucket, and reports it on the website.
Hi all,
I asked ChatGPT if it could do exactly what the title says. It gave me all the code to do so, and I filled in the areas that need to be done. But after deploying both the worker and website via Pages it won't work.
My website reports a CORS error in the console, and I get an error 1101 with the logs of my worker stating
env.MY_BUCKET.list(...) is not a function or its return value is not async iterable.
Attached is a photo on what the console for my website reports, a screenshot on what the logs for the worker say, and also the code I used to make it all work.
Help would be appreciated please! 🙏
Thanks.
P.S., I censored out anything I thought was personal, but please let me know if anything is needed.2 Replies
hi all, i fixed the cors error and now i'm just getting
Internal error: env.MY_BUCKET.list(...) is not a function or its return value is not async iterable as an error now. if anyone would be able to help that would be greately appreciatedI'd recommend looking at the example in https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#r2listoptions
Cloudflare Docs
Workers API reference
The in-Worker R2 API is accessed by binding an R2 bucket to a Worker. The Worker you write can expose external access to buckets via a route or manipulate R2 objects internally.
