R2 objects giving 404 unless I use double-slash after my hostname
Okay so, whenever I try accessing objects through my custom domain (say cdn.example.com), they're all giving me a 404 error. I access them like this: https://cdn.example.com/object
I then decided to check the objects on the control panel. There was a list of urls (my domain and the S3 API domain) and they all had a double slash after the hostname. Because of this, I tried accessing my object like this: https://cdn.example.com//object and that actually worked.
Any ideas on how to fix this so I can access objects with just a single slash (as URLs are supposed to be)?
8 Replies
Do you write your objects with a slash at the start of them? I would assume you are given that would be the only way the url would start with
//
remove the /
from the start of your object key and you should be goodI tried uploading an object through the panel as well, didn't work either
although I did upload it in a folder, so if the folder as a whole is messed up then that would explain it
oh that explains it
huh that's strange, I put a log statement to see what I'm sending to my AWS library as the Key and it doesn't even have a leading slash
it looks like there's an object called
/
and that's what's causing the cdn.domain.com//
yeah I can see that, my question is why
accidental creation?
just wipe it and upload something new right there, then test
unless there's stuff in it
I'm using the lib from this guide
https://developers.cloudflare.com/r2/examples/aws/aws-sdk-js-v3/
I assume I had a trailing slash in my endpoint but it'd be strange if the library doesn't properly handle that case
either way i'm waiting for docker hub to go back up so I can redeploy my backend with the R2 credentials and reupload my files
also yes, uploading a file to the root works fine so it's probably something to do with the lib
is there any way to mass-delete objects?
also yeah for some weird reason everything gets pushed to that
/
object and idk why
my keys don't even start with / when I give them to the library
wait I think I know what's going on
I'm using path.join to generate my paths and I feel like on windows it doesn't add a leading slash but on linux it does
yep I just made a sanitization function and used it to remove the leading slash
it work fine now