Need help with r2 in pages
I am trying to follow https://developers.cloudflare.com/pages/tutorials/use-r2-as-static-asset-storage-for-pages/ and it doesn't seem to be working.
I would expect such an asset to show up here: https://c4f64a53.sqm-website.pages.dev/tutorials/rig/v4/BPS_Rig_v4.zip
However I am getting this error in my build log.
Cloudflare Docs
Use R2 as static asset storage with Cloudflare Pages
This tutorial will teach you how to use R2 as a static asset storage bucket for your Pages app. This is especially helpful if you're hitting the file limit or the max file size limit on Pages.




41 Replies
Looks like your
wrangler.toml
is invalid?Thats what the log says but idk how to fix it tbh
Your
wrangler.toml
needs more than just what is mentioned there. https://developers.cloudflare.com/pages/functions/wrangler-configuration/Cloudflare Docs
Configuration
Pages Functions can be configured two ways, either via the Cloudflare dashboard or the Wrangler configuration file, a file used to customize the development and deployment setup for Workers and Pages Functions.
my workers.toml is the 3rd image
Looks like the minimum required is
name
and pages_build_output_dir
I was just following this

Might need to be more clear, but it means you need to add that to an existing config. It, on its own, isn't enough
Though also, we recommend using Workers instead of Pages if possible
tbh thats another thing I would need to learn we are just running a static html site
what do I put for
pages_build_output_dir
Wherever your files to be uploaded are placed, usually
dist
or similar
currently its blank on the sites side
Probably just "" then?
ill try

Looks like it completely skipped
wrangler
... weird
Not sure why that would happen tbh
Long guess, but maybe try
/
?Hm, yeah, not sure
didn't like
"./dist"
eitherWhat if you move all of the files you want to upload(minus your wrangler.toml) to
dist
first?or public? going over this and im kinda guessing they are using public as their build output dir?

Yeah, that's correct
alright imma give it a try
Just need a directory, doesn't really matter what name it is
still getting a 404 though


oh im dumb it is working I just needed to add a 2nd /tutorials/ https://fcac5a9e.sqm-website.pages.dev/tutorials/tutorials/rig/v4/BPS_Rig_v4.zip
Question is, Is there a way to change the root dir it starts inside our R2 storage?

Remove the replace?
remove this part or do you mean remove the whole line?

Yeah, just that part. Then any request to /tutorials/* would be routed to tutorials/* in your bucket, if that was what you were going for?
Or if you want a different subdirectory, you can change the folder the function is in
That doesn't seem to work.
To confirm I have it right, which directory do you want to serve from in your bucket, and which path prefix do you want to use on Pages?
In R2 we have a tutorials dir which goes into tutorials/rig/*

I was just wanting it to follow the dir structure of the bucket
https://squaredmedia.org/tutorials/rig/v4/BPS_Rig_v4.zip is the goal for what I want
https://32578f4d.sqm-website.pages.dev/ is running what you suggested but https://32578f4d.sqm-website.pages.dev/tutorials/rig/v4/BPS_Rig_v4.zip and https://32578f4d.sqm-website.pages.dev/tutorials/tutorials/rig/v4/BPS_Rig_v4.zip both 404
Squared Media
Official home of Squared Media and all its projects.
Squared Media
Official home of Squared Media and all its projects.

Ok, might be me being dumb, but could you do
.pathname.slice(1)
? That should remove the first slash from the pathWhere would that go?
Like this:
That solved my issue thank you 🙂