Is it me or does the SDK always return a image URL...
# off-topic
j
Is it me or does the SDK always return a image URL even if the file doesn't exist? This seems odd to me.
Copy code
await supabase.storage
  .from('public')
  .getPublicUrl('file-that-does-not-exist.png')
Uh oh.. yeah so it's hardcoded in the SDK:
Copy code
getPublicUrl(
    path: string
  ): {
    data: { publicURL: string } | null
    error: Error | null
    publicURL: string | null
  } {
    try {
      const _path = this._getFinalPath(path)
      const publicURL = `${this.url}/object/public/${_path}`
      const data = { publicURL }
      return { data, error: null, publicURL }
    } catch (error) {
      return { data: null, error, publicURL: null }
    }
  }
What's the best way to see if an image exists?
a
Maybe read from the storage.objects table?
You can run select * from storage.objects; in the SQL editor.
j
Oh yeah, true! I guess I could create a helper function.
I ended up using fetch(publicURL) and check if I get a 200 response
Just need to whip up something real quick
Thanks for the idea @User