0

I want to build chat app like whatsapp using android. I want to use firebase as file storage for send file feature. Can I use firebase as file storage?

  • 1
    Yes, you can use definitely. – Pratik Butani Feb 06 '19 at 04:35
  • If you consider at some point to try using [Cloud Firestore](https://firebase.google.com/docs/firestore/), here you can find a tutorial on how to create a complete and functional [Firestore Chat App](https://www.youtube.com/playlist?list=PLn2n4GESV0Ak1HiH0tTPTJXsOEy-5v9qb). – Alex Mamo Feb 06 '19 at 11:46
  • @PratikButani [Firebase Database](https://firebase.google.com/docs/database/) is not really appropriate for file storage due to the node capacity limits. However, [Cloud Storage](https://firebase.google.com/docs/storage/) is the perfect solution for storing images, files etc. and is used in conjunction with the Firebase Database or Cloud Firestore. You may have meant that but *Firebase* is a suite of services so I wanted to add some details. – Jay Feb 06 '19 at 22:25
  • @Jay Thanks for your words but I didn't say that use *Firebase Database* for File Storage. As he asked for `Can I use firebase as file storage?` and I said yes. – Pratik Butani Feb 07 '19 at 04:24
  • @PratikButani Firebase isn't the name of a specific product, so I wanted to ensure they understand the limitations and higher costs of using Firebase Realtime Database for storage instead of Firebase Storage, which is what that product is designed for. – Jay Feb 07 '19 at 18:00

2 Answers2

0

Can I use firebase as file storage?

Yes, why not!

Beware of the Pricing

The article-> Using Firebase to create a “simple” Chat application in Android will walk you through the prerequisites too.

And

Should you choose a Firebase Database For Your App: Realtime Database vs. Cloud Firestore

Daksh Gargas
  • 3,498
  • 2
  • 23
  • 37
  • This is not correct. Firebase Realtime Database is NOT a good solution for file storage as there is a 10Mb limit in a node. However, Firebase Cloud Storage is, which is a different product than Firebase (which is what the OP is asking about for his Chat app). – Jay Feb 06 '19 at 22:27
  • And see a Firebaser's answer [here](https://stackoverflow.com/questions/36718006/handling-image-store-to-firebase-with-swift). Too elaborate a bit, images and files are static data and that's not what Firebase Realtime Database or even Firestore is about - they are about dynamic, changing data. So if you choose to store static data in those databases you are paying a premium for a dynamic database to store static data. Much better (and less expensive) to utilize Cloud Storage for static data. – Jay Feb 06 '19 at 22:33
  • Hi, I completely understand your point. But I just answered the question. XMPP framework will suit his requirement best. But what if he only wants to build a demo application, like for his school project? I'm sure, if he really want to build a startup out of it, he'll surely build his own server. – Daksh Gargas Feb 07 '19 at 04:12
  • And of course, as the name suggests -> FIREBASE CLOUD MESSAGING (https://firebase.google.com/docs/cloud-messaging/) – Daksh Gargas Feb 07 '19 at 04:12
  • @Jay, also if you'll read the question.. he specifically mentioned that he wants to use Firebase as file storage.. so I guess I can't really do much about it. – Daksh Gargas Feb 07 '19 at 04:14
  • Understood. While it is an answer, the 'why not' portion is important as it will cost a LOT more, will only be able to store small files and there will be a performance hit as that's not what the Realtime Database was designed for. If the OP does go down the path of attempting to use RTDB for storage, he will have to re-code all of that later. Doing it with Storage up front is a better direction and won't impact the chat function. If you haven't already done so, check out the link I included above and read through @FrankvanPuffelen answer and the links he included. It's got some great info. – Jay Feb 07 '19 at 18:05
  • Thanks, I'll keep that in mind. Feel free to update my answer :) – Daksh Gargas Feb 07 '19 at 18:07
0

Yes definitely you can use Firebase Storage for storing files (images,videos,text,etc).

So in order to upload a file to Firebase Storage, first make a instance of FirebaseStorage class like

FirebaseStorage mFirebaseStorageReference = FirebaseStorage.getInstance().getReference().child("folderName");

Now for sending the file, you must first get the file maybe from the phone storage so use an intent for that. Now whatever image you have received, just make that image the child of the your mFirebaseStorageReference.

So it would look like this:

*folderName

*imageName(child of folderName, meaning inside folderName folder).

Then use putFile method for uploading the data to the FirebaseStorage like:

Say you created a new instance of your new file like mNewFileStorage

mNewFileStorage.putFile(uri).addOnSuccessListener(listener);
Sagar Balyan
  • 620
  • 6
  • 20