Storage
"firebase/storage"
"firebase-admin/storage"
Google's infrastructure
Firebase Storage is a wrapper around Google's Cloud Storage service: https://cloud.google.com/storage/?hl=en, which is similar to Amazon S3.
As other storage providers, it uses the concepts of objects living in a bucket.
objects in a bucket
we use the term object instead of file to emphasize some differences:
- objects are immutable. If we want to save a modified version, we must create a new, distinct object. We may keep or delete the former object. This is distinct from files that are writable and may change over time.
- objects live in a single, flat container, which is different from most file systems where a file lives somewhere in a vertical hierarchy made of nested directories. The flat layout is simpler and makes it easier for providers to scale.
- bucket is the name given to such flat container. Within a bucket, we may emulate a hierarchy by adding subpaths in the file name such as public/ in
public/abc.png
bucket globally unique identifier
The name of the bucket uses the form of an URL. The project ID, which is unique, makes the URL unique.
projectname.appspot.com
PROJECT_ID.firebasestorage.app
We may not use the URL as-is to access the content. Instead, the access HTTP requests typically embed this URL within a bigger one.
the extended ID may use the gs://
prefix
"gs://projectname.appspot.com"
client SDK: specify a bucket
A firebase project is given a default bucket. The storage service picks the default bucket by default.
const storage = getStorage(app)
If we are to use a distinct bucket, we must provide its ID.
const storage = getStorage(app, bucketID)
const storage = getStorage(app, "gs://my-custom-bucket")