Get started with Cloud Storage on Android – Firebase

Cloud Storage for Firebase lets you upload and share user generated content, suchas images and video, which allows you to build rich media content into yourapps. Your data is stored in aGoogle Cloud Storage bucket anexabyte scale object storage solution with high availability and globalredundancy. Cloud Storage for Firebase lets you securely upload these filesdirectly from mobile devices and web browsers, handling spotty networks withease.

If you haven't already,add Firebase to your Android project.

From the navigation pane of the Firebase console, select Storage,then click Get started.

Review the messaging about securing your Cloud Storage data using securityrules. During development, considersetting up your rules for public access.

Select a location for your defaultCloud Storage bucket.

This location setting is your project'sdefault Google Cloud Platform (GCP) resource location.Note that this location will be used for GCP services in your projectthat require a location setting, specifically, yourCloud Firestore database and yourApp Engine app(which is required if you use Cloud Scheduler).

If you aren't able to select a location, then your project alreadyhas a default GCP resource location. It was set either during projectcreation or when setting up another service that requires a locationsetting.

If you're on the Blaze plan, you cancreate multiple buckets, each with its ownlocation.

Click Done.

Cloud Storage for Firebase provides a declarative rules language that allows youto define how your data should be structured, how it should be indexed, and whenyour data can be read from and written to. By default, read and write access toCloud Storage is restricted so only authenticated users can read or writedata. To get started without setting up Authentication, you canconfigure your rules for public access.

This does make Cloud Storage open to anyone, even people not using yourapp, so be sure to restrict your Cloud Storage again when you set upauthentication.

By using the Firebase Android BoM, your app will always use compatible versions of Firebase Android libraries.

(Alternative) Add Firebase library dependencies without using the BoM

If you choose not to use the Firebase BoM, you must specify each Firebase library version in its dependency line.

Note that if you use multiple Firebase libraries in your app, we strongly recommend using the BoM to manage library versions, which ensures that all versions are compatible.

By using the Firebase Android BoM, your app will always use compatible versions of Firebase Android libraries.

(Alternative) Add Firebase library dependencies without using the BoM

If you choose not to use the Firebase BoM, you must specify each Firebase library version in its dependency line.

Note that if you use multiple Firebase libraries in your app, we strongly recommend using the BoM to manage library versions, which ensures that all versions are compatible.

The first step in accessing your Cloud Storage bucket is to create aninstance of FirebaseStorage:

You're ready to start using Cloud Storage!

First, let's learn how to create a Cloud Storagereference.

There are a few use cases that require additional setup:

The first use case is perfect if you have users across the world, and want tostore their data near them. For instance, you can create buckets in the US,Europe, and Asia to store data for users in those regions to reduce latency.

The second use case is helpful if you have data with different access patterns.For instance: you can set up a multi-regional or regional bucket that storespictures or other frequently accessed content, and a nearline or coldline bucketthat stores user backups or other infrequently accessed content.

In either of these use cases, you'll want touse multiple Cloud Storage buckets.

The third use case is useful if you're building an app, like Google Drive, whichlets users have multiple logged in accounts (for instance, a personal accountand a work account). You canuse a custom Firebase Appinstance to authenticate each additional account.

If you want to use a Cloud Storage bucket other than the default provided above,or use multiple Cloud Storage buckets in a single app, you can create an instanceof FirebaseStorage that references your custom bucket:

When importing an existing Cloud Storage bucket into Firebase, you'llhave to grant Firebase the ability to access these files using thegsutil tool, included in theGoogle Cloud SDK:

You can find your project number as described in the introduction toFirebase projects.

This does not affect newly created buckets, as those have the default accesscontrol set to allow Firebase. This is a temporary measure, and will beperformed automatically in the future.

If you're building a more complicated app using a custom FirebaseApp, you cancreate an instance of FirebaseStorage initialized with that app:

See more here:
Get started with Cloud Storage on Android - Firebase

Related Posts

Comments are closed.