Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: signed url for public bucket

Qiao Han6441c85801c3
diff --git a/studio/pages/api/storage/[ref]/buckets/[id]/objects/public-url.ts b/studio/pages/api/storage/[ref]/buckets/[id]/objects/public-url.ts
index 41efb4e8107..40a23910b6a 100644
--- a/studio/pages/api/storage/[ref]/buckets/[id]/objects/public-url.ts
+++ b/studio/pages/api/storage/[ref]/buckets/[id]/objects/public-url.ts
@@ -24,5 +24,12 @@ const handlePost = async (req: NextApiRequest, res: NextApiResponse) => {
const { data } = supabase.storage.from(id as string).getPublicUrl(path)
+ // change the domain name to the SUPABASE_PUBLIC_URL since SUPABASE_URL is not accessible from the client
+ const publicUrl = new URL(data.publicUrl)
+ const parsed = new URL(process.env.SUPABASE_PUBLIC_URL!)
+ publicUrl.protocol = parsed.protocol
+ publicUrl.host = parsed.host
+ data.publicUrl = publicUrl.href
+
return res.status(200).json(data)
}
diff --git a/studio/pages/api/storage/[ref]/buckets/[id]/objects/sign.ts b/studio/pages/api/storage/[ref]/buckets/[id]/objects/sign.ts
index c89791ab5f3..f976c44b822 100644
--- a/studio/pages/api/storage/[ref]/buckets/[id]/objects/sign.ts
+++ b/studio/pages/api/storage/[ref]/buckets/[id]/objects/sign.ts
@@ -29,7 +29,9 @@ const handlePost = async (req: NextApiRequest, res: NextApiResponse) => {
// change the domain name to the SUPABASE_PUBLIC_URL since SUPABASE_URL is not accessible from the client
const signedUrl = new URL(data.signedUrl)
- signedUrl.host = new URL(process.env.SUPABASE_PUBLIC_URL!).host
+ const parsed = new URL(process.env.SUPABASE_PUBLIC_URL!)
+ signedUrl.protocol = parsed.protocol
+ signedUrl.host = parsed.host
data.signedUrl = signedUrl.href
return res.status(200).json(data)