Kotlin 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 Posts:
- Kotlin Firebase Storage – Upload Data from Memory, Local File, Stream | Android
- Kotlin Firebase Storage – Get List of Files example – Image List with FirebaseRecyclerAdapter | 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 Storage to Android App & enable Firebase Auth, please visit previous post:
Kotlin 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
// From our app
val storageRef = storage.getReference()
// With an initial file path and name
val pathReference = storageRef.child("images/javasampleapproach.jpg")
// To a file from a Google Cloud Storage URI
val gsReference = storage.getReferenceFromUrl("gs://javasampleapproach-storage.appspot.com/images/javasampleapproach.jpg")
// From an HTTPS URL
val httpsReference = storage.getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/javasampleapproach-storage.appspot.com/o/images%2Fjavasampleapproach.jpg")
2. Download Data using
2.1 getBytes()
More at:
Kotlin Firebase Storage – Download Files to Memory, Local File | Android
Top comments (0)