Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPublicUrl does not check if file exists #279

Closed
jstdk opened this issue Nov 18, 2022 · 3 comments
Closed

getPublicUrl does not check if file exists #279

jstdk opened this issue Nov 18, 2022 · 3 comments
Labels
bug Something isn't working storage This issue or pull request is related to storage

Comments

@jstdk
Copy link

jstdk commented Nov 18, 2022

Describe the bug
Not sure this is a bug or a feature, but the Storage function getPublicUrl always returns a public url, even is the file does not exist. Firebase Storage provides a null in that scenario, which can then be used in the application to show an upload form. With the current Supabase flow, I need to test myself if the file exists (not sure how to be honest) and then show a form.

To Reproduce
Create a bucket, make it public, leave it empty. Create a function to query a specific file
image
image

Expected behavior
A response that either errors or nulls

Screenshots
image

Smartphone (please complete the following information):

  • Version 1.1.0, Flutter 3.3.8

Additional context
Repo: https://github.com/jstdk/starter

@jstdk jstdk added the bug Something isn't working label Nov 18, 2022
@dshukertjr
Copy link
Member

@jstdk
getPublicUrl is just a method that constructs a url from given parameters such as supabase url, bucket name, and path, so no it does not check if a file exists or not.

You can use the createSignedUrl method to get a URL if a file exists, or throw an error if it does not exist.

@dshukertjr dshukertjr added the storage This issue or pull request is related to storage label Nov 18, 2022
@Vinzent03
Copy link
Collaborator

@dshukertjr But isn't createSignedUrl only for private buckets useful? Isn't creating your own exists function more suited? See supabase/storage#266

@dshukertjr
Copy link
Member

dshukertjr commented Nov 18, 2022

@Vinzent03 @jstdk You can still use createSignedUrl on public buckets. Also, in the original issue, it brings up how Firebase storage is able to detect whether a file exists or not. In Firebase storage, every URL it returned is a signed URL, so the use case is exactly the same as calling createSignedUrl to see if there is a file there on Supabase.

If you don't want to use createSignedUrl, nothing is stopping you from making a HTTP request to the URL to see if it returns 404 or not. You could make a HTTP HEAD request to efficiently see if a file exists or not.

@jstdk jstdk closed this as completed Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working storage This issue or pull request is related to storage
Projects
None yet
Development

No branches or pull requests

3 participants