Upload Image to Firebase Storage | Android App Development | Lecture#60 | Hive Learners

in Hive Learners • 5 months ago


Hello Hive Learners, I hope you all are well and doing good. In lecture 59 we learn how to configure the Firebase Storage to our Android Project. We used Firebase Assistance to add useful dependencies. We also declare and initialize the FirebaseStorage and StorageReferences variables. Today we will learn to upload an image to Firebase Storage and we will create an upload function so we can reuse it anywhere. So let's get started.

GitHub Link

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

What Should I Learn

  • How to upload the image to Firebase Cloud Storage


  • Upload image to Firebase Cloud Storage


First, we need to create a function upload_image we will pass a parameter Uri to this function so that whenever we call this function with a Uri it will upload that Image Uri to Storage.

Move the upload image code in this function and use the passed parameter in place of null.

Now we need to call this function when a user gets an image successfully. We need to provide the image Uri to this function so that image can be uploaded to Firebase Storage. We also need to create Firebase Storage Bucket from the Firebase console.

If it asks for rules then start in test mode.

Here are the test rules.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write//: if false;

We need to sign in otherwise we will get a token error. So when the account is created successfully then we can upload the image to Firebase Storage, Here I check it after login success but for the test, I use the Signup page as we have an upload image function after the image selection. After uploading the image we can see the image in the Firebase Storage. It is named profile_image. It means the reference is used as the name of the image. We will set a unique image name in part-2 of this lecture. We will use the Firebase auth token as the image name for a user profile image.


Thank You



Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.