1

I have tried with converting uri object to string, but that won't work (obviously). If it is possible, can you tell me how or give me some links to watch some tutorial?

Nikola
  • 109
  • 1
  • 3
  • 13
  • This was asked a few hours ago. Please search for an existing question before entering your own. – Frank van Puffelen Mar 20 '16 at 21:35
  • *Firebase just released a new feature called [Firebase Storage](https://firebase.google.com/docs/storage/). This allows you to upload images and other non-JSON data to a dedicated storage service. We highly recommend that you use this for storing images, instead of storing them as base64 encoded data in the JSON database.* – Frank van Puffelen May 20 '16 at 04:26
  • Yes firebase storage is a good option for storing images but can you give a reason to not store images as base64 encoded data in the JSON database. – Parag Kadam Jul 26 '17 at 05:47

1 Answers1

6

Yes Firebase supports storing images, since they're only binary files.

All you need to do is to convert your image to base64 then store it like any other data.

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, stream);
byte[] byteFormat = stream.toByteArray();
String encodedImage = Base64.encodeToString(byteFormat, Base64.NO_WRAP);

Then to display your image :

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 
myimageview.setImageBitmap(decodedByte);
Mehdi Sakout
  • 773
  • 5
  • 8