How to enable “Share publicly” when uploading a file to Firebase storage?

后端 未结 1 1560
抹茶落季
抹茶落季 2021-01-13 08:45

Firebase Storage uses Google Cloud Platform for storage. GCP allows the option \"Share publicly\" on files to be able to view such files in a browser.

Here is the GC

1条回答
  •  野的像风
    2021-01-13 09:20

    With Firebase Storage, you're given two URLs that you can use to represent files:

    // "Private" internal URL, only accessible through Firebase Storage API
    // This is protected by Firebase Storage Security Rules & Firebase Auth
    gs://bucket/object
    
    // "Public" unguessable URL, accessible by anyone with the link
    // This is secured because that token is *very* hard for someone to guess
    https://firebasestorage.googleapis.com/v0/bucket/object?alt=media&token=
    

    The second option allows you to share this public but unguessable URL with trusted individuals, and allows them to access content without authentication to Firebase or using your app--think sharing family photos with Google Photos. Likely this behavior will be good enough, unless you desire public sharing with clean URLs.

    The third option, as you mention, involves going directly to the Google Cloud Storage console and making files publicly available with a clean URL, which isn't available via the Firebase Storage client. This would add a third URL:

    // "Public" clean URL, accessible and guessable
    // Not secure, typically used for public, static content
    https://storage.googleapis.com/v0/bucket/object
    

    Generally speaking, unless you want people to know and guess your content (hosting static content, website files, etc.), I would not share publicly via GCS, and almost definitely wouldn't go so far as to set the default ACL to always be public (what happens if you add a new feature and no longer want this behavior, you may forget to turn this back off again...).

    0 讨论(0)
提交回复
热议问题