Firebase Storage – Download Files to Memory, Local File | Android

In previous post, we had known the way to upload data. This tutorial shows you how to download Files to Memory, Local File with Firebase Cloud Storage.

Related Post:
Firebase Storage – Upload Data from Memory, Local File, Stream | Android

More Practice:
Firebase Storage – Get List of Files example – Image List | Android

I. How to download file

To use the Firebase Storage to download file, we need:
– add Firebase to Android App & enable Firebase Auth
– create a reference to the full path of the file, including the file name
– download file using getBytes() for in-memory data, getFile() for local file.

To know way to add Firebase to Android App & enable Firebase Auth, please visit previous post:
Firebase Storage – Upload Data from Memory, Local File, Stream | Android

This tutorial bases on the code from that post, and continues with download methods.

1. Create a Reference

2. Download Data using
2.1 getBytes()

getBytes() method is the easiest way to download a file, it must load the entire into memory.
If we request a file larger than available memory, the app will crash. So we should set the maximum size, or use another download method.

2.2 getFile()

When we wanna access the file while offline or to share the file in a different app, we use getFile(). It returns a DownloadTask to manage download and monitor the status of the download:

II. Practice

1. Goal

We will build an Android App that can:
– create Account, sign in/sign out for Firebase Authentication.
– choose image from Gallery, then upload it to Firebase Cloud Storage using putBytes(), putStream() and putFile() methods.
(previous post’s functions)
– download file (image) that is uploaded recently using getBytes(), getFile() methods, then display it.


2. Technology

– Gradle 2.3.3
– Android Studio 2.x
– Firebase Android SDK 11.x

3. Project Structure


LoginActivity is for Authentication, then user can change to StorageActivity to upload/download image to Firebase Cloud Storage.

4. Step by step
4.1 Create Android Project

– Generate new Android Project with package com.javasampleapproach.firebasestorage.
build.gradle (project-level):

build.gradle (App-level):

4.2 Create Firebase Project & Add Firebase Config file

– Follow this guide to generate google-services.json file and move it into your Android App root directory. You don’t need to have SHA-1 Key in this example, just leave it blank.

– Make sure that package_name in google-services.json has a correct value according to:
+ applicationId in build.gradle (App-level).
+ package in AndroidManifest.xml.
In this case, it is com.javasampleapproach.firebasestorage.


4.3 Enable Firebase Auth

Go to Your Firebase Project Console -> Authentication -> SIGN-IN METHOD -> Enable Email/Password.

4.4 LoginActivity

To know how to implement Firebase Authentication App Client, please visit:
Firebase Authentication – How to Sign Up, Sign In, Sign Out, Verify Email | Android

In this tutorial, we don’t explain way to authenticate an user again.

4.5 StorageActivity

4.6 Android Manifest

4.7 Run & Check result

Use Android Studio, build and Run your Android App:


III. Source code


By grokonez | August 18, 2017.

Last updated on July 13, 2018.

Related Posts

3 thoughts on “Firebase Storage – Download Files to Memory, Local File | Android”

  1. I tried hard but I got the following error. Do you happen to know the solution?

    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.yehyo.rererestart, PID: 20843
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.yehyo.rererestart/com.example.yehyo.rererestart.StorageActivity}; have you declared this activity in your AndroidManifest.xml?
    at com.example.yehyo.rererestart.MainActivity.testStorage(
    at com.example.yehyo.rererestart.MainActivity.onClick(
    at android.view.View.performClick(
    at android.view.View$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)
    Application terminated.

    1. Hi Hyony Park,

      Have you declared StorageActivity activity in your AndroidManifest.xml? 🙂


  2. Hi, Tutorial is quite helpful and thank you. and I need ur suggestion on below question

    I have a cloud function which gives me signed url of the image in firebase storage, So how can i download that file into my external sdcard using signed url.

    Can i use getFile method and use signed url instead of download url, will it work, could you advise.

Got Something To Say:

Your email address will not be published. Required fields are marked *