KEMBAR78
Proposal: Instantiate a File using Public URL · Issue #1898 · googleapis/nodejs-storage · GitHub
Skip to content

Proposal: Instantiate a File using Public URL #1898

@GabrielBB

Description

@GabrielBB

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 just file(options: FileOptions): File

2 - Extend FileOptions like:

interface FileOptions {
    name?: string,
    publicUrl?: string,
    ...
}

3- Extract the name from the public url:

If name is not filled, we can proceed and check publicUrl -> From https://storage.googleapis.com/${firebase-project}.appspot.com/images%2Ftest.jpeg extract just images%2Ftest.jpeg, decode it as images/test.jpeg and use it as name. This would require doing a split: We already know the host is a static https://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" }) and file({ 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: storageIssues related to the googleapis/nodejs-storage API.priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions