https://github.com/m4ary/firebasestorageapi
Android Library wrapper for Firebase Storage functionality.
https://github.com/m4ary/firebasestorageapi
android android-app android-application android-development android-library android-studio android-ui androidstudio firebase firebase-database firebase-hosting firebase-realtime-database firebase-storage
Last synced: about 2 months ago
JSON representation
Android Library wrapper for Firebase Storage functionality.
- Host: GitHub
- URL: https://github.com/m4ary/firebasestorageapi
- Owner: m4ary
- License: mit
- Created: 2020-05-15T22:30:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-09T06:37:51.000Z (about 5 years ago)
- Last Synced: 2025-09-15T02:45:17.353Z (9 months ago)
- Topics: android, android-app, android-application, android-development, android-library, android-studio, android-ui, androidstudio, firebase, firebase-database, firebase-hosting, firebase-realtime-database, firebase-storage
- Language: Java
- Homepage:
- Size: 2.27 MB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FirebaseStorageAPI [](https://jitpack.io/#mshlab/FirebaseStorageAPI)
FirebaseStorageAPI is an Android Library wrapper for Firebase Storage functionality.

## Features
- built-in Progress Dialog
- customizable messages fit your need and language
- Upload and download files to Firebase Storage Bucket in different forms like:
- stream as an IntputStream
- Array of Bytes
- File on Device Storage
- Delete files
## Download
### 1- Setup Firebase Storage
Add Firebase Storage library to your Firebase project
[https://firebase.google.com/docs/storage/android/start](https://firebase.google.com/docs/storage/android/start)
### 2-Add Gradle dependency
- Add the following to your project level build.gradle:
~~~
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
~~~
- Add this to your app build.gradle:
~~~
dependencies {
...
implementation 'com.github.mshlab:FirebaseStorageAPI:v1.0-release'
}
~~~
## Usage
1- create a FirebaseStorageAPI object
~~~
FirebaseStorageAPI firebaseStorageAPI = new FirebaseStorageAPI.Builder()
.setVisibleAcitivty(this) //required
.build();
~~~
- add more custom options
~~~
firebaseStorageAPI = new FirebaseStorageAPI.Builder()
.setVisibleAcitivty(this) //required
.setCancelMessage("file download canceled")
.setDownloadingMessage("downloading from the sky")
.setErrorMessage("error in gating the file, try later")
.setUploadingMessage("carrying it to cloud")
.setLoadingMessage("waiting to start")
.allowCancel(true) //let the user choose to cancel the download
.build();
~~~
2- defined a storage reference (path where you will upload or download your file) [learn how](https://firebase.google.com/docs/storage/android/create-reference)
~~~
StorageReference mStorageRef = FirebaseStorage.getInstance().
getReference().
getRoot().
child("pics").
child("sky.png");
~~~
**A- Upload function**
1- prepare the data as :
- inputstream
~~~
InputStream DataToUpload = ...;
~~~
- File
~~~
Uri DataToUpload = Uri.fromFile(new File("/sdcard/hello.txt"));
~~~
- Bytes
~~~
String string = "helloWorldInBytes";
byte[] DataToUpload=string.getBytes();
~~~
2- pass it to `upload` method
~~~
firebaseStorageAPI.upload(DataToUpload, mStorageRef, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
mStorageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(Uri ) {
statusTextView.setText("file uploaded successfully\n File URL: " + uri.toString());
}}); }} });
~~~
**B- Download function**
- InputStream
~~~
firebaseStorageAPI.downloadAsStream(mStorageRef, new OnCompleteListener() {
@Override
public void onComplete(@NonNull final Task task) {
if (task.isComplete()) {
InputStream is = task.getResult().getStream();
//InputStream is ready to use
}
}
});
~~~
- File
~~~
File localFile = File.createTempFile("images", "jpg");
firebaseStorageAPI.downloadToLocalPath(mStorageRef, localFile, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isComplete()) {
// download is complete, do your thing with the localFile ...
}
}
});
~~~
- Bytes
~~~
firebaseStorageAPI.downloadAsBytes(mStorageRef, Long.MAX_VALUE, new OnCompleteListener({
@Override
public void onComplete(@NonNull Task task) {
if (task.isComplete()) {
byte[] dataInBytes = task.getResult();
// download complete , do your thing with the dataInBytes
}
}
});
~~~
