storage.getPublicUrl seems to be broken
kaspnilsson opened this issue · 5 comments
I have code like this:
const { data, error } = await supabase.storage
.from('public-bucket')
.upload(uuid(), file)
if (error) {
onError(error)
return
}
const res = supabase.storage.from('public-bucket').getPublicUrl(data?.Key)
if (res.error) {
onError(res.error)
return
}
onSuccess(res.publicURL)
The value of data
is an object that looks like this:
{ Key: 'public-bucket/dv_iPhZFUFIeGk0a' }
Then, when I call getPublicUrl with the value of data.Key
, I get a URL that looks like this: [REDACTED_SUPABASE_URL]/storage/v1/object/public/public-bucket/public-bucket/dv_iPhZFUFIeGk0a
Uploading works fine, but the getPublicUrl implementation seems to be doubly prefixing the bucket name.
Currently working around it by just creating the public URL myself via string concatenation.
const SUPABASE_STORAGE_BUCKET_URL =
`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/\`
...
onSuccess(`${SUPABASE_STORAGE_BUCKET_URL}${data.Key}`)
getPublicUrl wants the filepath not the key. That is everything after the bucket, folders and filename.
Hmm, could we consider reconfiguring the output of upload
or somehow otherwise making it more obvious how you use these APIs in conjunction?
thanks for reporting @kaspnilsson have moved to storage-js and relabelled as enhancement. At some point we might want to revisit the API, feel free to make suggestions on the design if you want to drive this forward 👍
Not quite a dupe, will elaborate there :)