Generate R2 Objecs Public URL

I would like to retrieve the public url once the upload is completed, but I am getting a url with some headers X-Amz-Date and like those, I want to list my pdfs to my public website.
// Generate a public URL for the uploaded file
const publicUrl = r2.getSignedUrl('getObject', {
Bucket: process.env.R2_BUCKET,
Key: fileName,
});
// Generate a public URL for the uploaded file
const publicUrl = r2.getSignedUrl('getObject', {
Bucket: process.env.R2_BUCKET,
Key: fileName,
});
Correct me if that's okay to use such url and expose to public.
4 Replies
harshil1712
harshil17123d ago
Hey, this is a pre-signed URL. Not sure if that's what you are looking for
ayushh
ayushhOP3d ago
I am not sure what that means I am just looking for a public url that I can fetch and display it on my frontend
harshil1712
harshil17123d ago
You can setup your domain and to make your bucket public. You can access the file with something like: sub.domain.tld/file/key
ayushh
ayushhOP2d ago
okay

Did you find this page helpful?