code
I'm following the example but I seem to get nested folders, is this intentional?

25 Replies
I suppose you read Kian’s response, but yeah this is expected. There’s no such thing as “folders” really, the dashboard just uses / as a delimiter to fake them.
I'm a bit confused, when I then try to get the info of the file
even though /camcorder-ai/file.mp4 is what I was returned back from the S3 command
I think the leading ‘/‘ is what your problem is
camcorder-ai/file.mp4 exists, but /camcorder-ai/file.mp4 does not.
I’m going off the dashboard screenshot above
I don't add the /camcorder-ai/ to any of my file upload code at all so I'm confused where it's coming from
How are you uploading these files? Some tools like to prefix object names with the bucket’s name.
Is this the S3 SDK?
aws s3 sdk yeah
code here
Try setting the “forcePathStyle” key in your config to false?
didn't know that was a thing, will try it!
Yeah so S3 (and consequentially R2) has two ways of addressing buckets, one where the bucket name is in the hostname, bland another where the bucket name is in the path.
Hostname style domains would look like: <bucketName>.<accountId>.r2.cloudflarestorage.com, and “path style” hostname would look like: <accountId>.r2.cloudflarestorage.com/<bucketName>.
I bet you use the hostname variant as your S3_ENDPOINT env var, but S3 thinks you’re using the pathname variant (which is the default)
ooohh
that explains a lot
So it sends requests to <bucketName>.<accountId>.r2.cloudfalrestorage.com/<bucketName>/<objectKey>. That’s where the extra “camcorder-ai” is likely coming from.
You can either set forcePathStyle to false, or switch your endpoint URL
I set it to false but it still seems to do path style
ohhh wait
is it because the endpoint here?
Ha yeah
Remove the bucket name from there, the SDK will add it automatically
as an environment var?
oh
you mean in the endpoint
Yep, this should work as expected
thank you
my god this has been annoying to debug
i was like I'm uploading files to root but a folder gets added
but then when I retrieve files I can't have the folder in the string!
Yeah haha unfortunately we can't make this "easier", this is just the S3 API contract
gotcha
well thank you for explaining it to me
No probs! I think this should explain your 404s as well
perfect, I can now go through and remove the weird parsing I had to do on my keys to remove the "fake" folder

@sdnts 


i finally got something to upload to root
Yay, nice!