2. Why Firebase ?
Build apps fast, without
managing infrastructure
One console, with products
that work together
Backed by Google, trusted by
top apps
Cloud Storage is built for app developers who need to store
and serve user-generated content, such as photos or videos.
FIREBASE STORAGE
3. How does it work?
Firebase Cloud Storage stores your files (Images or
Videos) in a Google Cloud Storage bucket.
These files can be accessible through both Firebase and
Google Cloud.
So developers choose firebase storage so that the
applications will be more flexible and user can upload
and download files from mobile devices. Developers
use Firebase SDKs for this.
FIREBASE STORAGE
4. How to implement ?
Integrate the Firebase
SDKs for Cloud Storage.
Create a Reference
Upload/Download
FIREBASE STORAGE
5. ImageView
Choose Upload
Lets create a project for more understanding.
For example, we want to select an image from
app and upload to Storage
FIREBASE STORAGE
6. 1. Configure
your Project
2. Add
Reference
points
3. Code For
Uploading File
Steps for implementation :
FIREBASE STORAGE
7. STEP 1 : Configure your Project
1. Click on TOOLS and select FIREBASE.
2. Click on Storage. => Click on Upload and
Download
a) Click on Connect to Firebase.
b) Click on Add Firebase Dependency.
FIREBASE STORAGE
9. STEP 2 : References point to files
In MainActivity.java, add
private StorageReference mStorageRef;
mStorageRef = FirebaseStorage.getInstance().getReference();
FIREBASE STORAGE
10. STEP 3 : Upload a File
Uri file = Uri.fromFile(new File("path/to/images/codekaksha.jpg"));
StorageReference riversRef = storageRef.child("images/rivers.jpg");
riversRef.putFile(file)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
Uri downloadUrl = taskSnapshot.getDownloadUrl();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
}
});
Add this code in onClickListener of Upload Button.
FIREBASE STORAGE
11. You can view the files in your storage bucket in the Firebase Console.
Click on STORAGE . Go to Rules, and change the rules to :
allow read, write: if true;
Your
Uploaded
File
FIREBASE STORAGE
12. REFERENCES :
• Add Firebase to your Project
https://firebase.google.com/docs/android/setup
• Firebase UI
https://github.com/firebase/FirebaseUI-Android
FIREBASE STORAGE