Use R2 public development URL

This commit is contained in:
Manohar Gupta 2026-05-10 14:35:11 +05:30
parent 864ecc2587
commit 4acd016b70

View file

@ -12,11 +12,8 @@ function getR2() {
throw new Error(`Missing R2 config`);
}
// Bucket is at subdomain: tia.<accountId>.r2.cloudflarestorage.com
// Or path: <accountId>.r2.cloudflarestorage.com/tia
const endpoint = bucket === "tia"
? `https://${bucket}.${accountId}.r2.cloudflarestorage.com`
: `https://${accountId}.r2.cloudflarestorage.com/${bucket}`;
// Use public development URL (from R2 bucket settings)
const pubBaseUrl = `https://pub-${accountId}.r2.dev/${bucket}`;
return {
client: new S3Client({
@ -25,7 +22,7 @@ function getR2() {
credentials: { accessKeyId, secretAccessKey: secretKey },
}),
bucket,
baseUrl: `https://${accountId}.r2.cloudflarestorage.com/${bucket}`,
baseUrl: pubBaseUrl,
};
}