Unable to upload image to R2 via workers
Hey folks
I am unable to upload an image to my R2 bucket with custom domain endpoints, using my workers api.
Here is my code. When executed, there is no error. And the web based dashboard doesn't shows the image in the bucket.
in my wrangler.toml file, I have bound the R2 details as
Since I am uploading from my workers api and not from a browser POST, I do not think I need to set anything like an AUTH_SECRET, or do I? I have also tried with and without CORS in the bucket settinsg without any success.
4 Replies
Furthermore, when I print the r2Object, the output suggests that the upload was successful. But I cannot see the images in my bucket via the dashboard, nor can I access them using the custom domain. Anything that I directly upload to the bucket using the web dashboard can be seen and accessed via the custom domain.
hey RIck, you don't need any auth secret nor cors settings when using the workers api. At first glance I don't see anything wrong with how you are storing the image. I have found this repo https://github.com/yusukebe/r2-image-worker you could try running it with your
assets
bucket configured and see if the images are being saved. At least it should help and tell you where to lookGitHub
GitHub - yusukebe/r2-image-worker: Store and Deliver images with R2...
Store and Deliver images with R2 backend Cloudflare Workers. - yusukebe/r2-image-worker
Thank you @.Mass. . I think I have found out the issue. I am doing local dev and my uploads are getting stashed in the local r2.
the linked repo helped me find that I need to use the
--remote
arg to use the cloud based r2 instance.
Would have helped if the R2 docs had this written anywhere. I found most of this info in the workers docs.@Rick I am glad you solved the issue. I agree, the docs are generally pretty good but miss some details here and there.