-
Notifications
You must be signed in to change notification settings - Fork 370
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
Proposal: Instantiate a File using Public URL #1898
Comments
Hi @GabrielBB , We will look into community / customer desire for this feature. |
Implementation idea if we decide to adopt this - this could be a static method on class File {
static from (publicUrl: string | URL, options: FileOptions): File {
// ...
}
} This way:
|
Sounds good |
Additional implementation note: should support |
@shaffeeullah Having an easy way to create a File instance would be so helpful to just be able to do:
|
The Python SDK already has a similar function |
Is your feature request related to a problem? Please describe.
Right now File can only be instantiated using the file name. However, is common for systems to save the entire file url in databases, in these cases, to later delete the file from the bucket you would need to extract the file name (including parent directories) from the public url. Which means that you would have to spend some time thinking how to properly do this and write unit tests for it. I would prefer if the library handles this for me.
Describe the solution you'd like
1 - Switch from
file(name: string, options?: FileOptions): File
to justfile(options: FileOptions): File
2 - Extend FileOptions like:
3- Extract the name from the public url:
If
name
is not filled, we can proceed and checkpublicUrl
-> Fromhttps://storage.googleapis.com/${firebase-project}.appspot.com/images%2Ftest.jpeg
extract justimages%2Ftest.jpeg
, decode it asimages/test.jpeg
and use it asname
. This would require doing a split: We already know the host is a statichttps://storage.googleapis.com
and the bucket name (${firebase-project}.appspot.com
) we already have it from here.Example of usage of proposed API
file({ name: "images/test.jpeg" })
andfile({ publicUrl: "https://storage.googleapis.com/${firebase-project}.appspot.com/images%2Ftest.jpeg" })
Describe alternatives you've considered
A backwards compatible way to achieve this would be to leave the API as it is but automatically recognise if
name
is a public url, in this case you would apply the same extraction logic mentioned before.I can offer myself to open the PR if you guys agree with one solution
The text was updated successfully, but these errors were encountered: