VOOZH about

URL: https://www.geeksforgeeks.org/android/android-how-to-upload-an-image-on-firebase-storage/

⇱ Android: How to Upload an image on Firebase storage? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Android: How to Upload an image on Firebase storage?

Last Updated : 12 Jul, 2025

Firebase is a mobile and web application development platform. It provides services that a web application or mobile application might require. Firebase provides secure file uploads and downloads for Firebase application. This article explains how to build an Android application with the ability to select the image from the mobile gallery and upload images to Firebase Storage.

Note: Firebase Storage now requires a billing plane to use Firebase Storage.

Step by Step Implementation

Step 1: Create a new project

Create a new project on android studio or open an existing project in which you want and add the firebase to that android application.

Step 2: Add the firebase storage dependency

Navigate to Gradle Scripts > build.gradle.kts (Module:app) and add the following dependencies

dependencies {
...
implementation("com.google.firebase:firebase-storage-ktx:21.0.1")
}


Step 3. Setting up the activity_main.xml layout file

Navigate to app > res > layout > activity_main.xml and add the following code

activity_main.xml:


Step 4: Working with MainActivity file

Navigate to app > java > {package-name} > MainActivity.kt/.java and add the following code.

Set OnClickListeners on the buttons to handle user interaction. When the Select button is clicked, a image selection bottom sheet is displayed using ActivityResultLauncher with ActivityResultContracts.GetContent. This launches a system image picker letting the user to choose an image from their device's gallery. Once the image is selected, its URI is returned, which is then displayed in the ImageView below the buttons.

When the Upload button is clicked, the uploadImage() method is called. Inside this method, a Firebase Storage reference is initialized and a unique file path is created using a UUID. If an image is selected, it is uploaded to Firebase using the putFile() function. A progress dialog shows the upload progress.


Output:

In App:

👁 Image


In Firebase console:

👁 Image


Comment

Explore