Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I store image files in firebase using Java API

Is there any way to store image files in firebase using Java api?

like image 829
Kabir Avatar asked Oct 10 '14 06:10

Kabir


1 Answers

Try using this snippet:

Bitmap bmp =  BitmapFactory.decodeResource(getResources(), R.drawable.chicken);//your image
ByteArrayOutputStream bYtE = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, bYtE);
bmp.recycle();
byte[] byteArray = bYtE.toByteArray();
String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); 

and for retrieving

public Bitmap stringToBitMap(String encodedString){
   try {
      byte [] encodeByte=Base64.decode(encodedString,Base64.DEFAULT);
      Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
      return bitmap;
   } catch(Exception e) {
      e.getMessage();
      return null;
   }
}
like image 161
sasuri Avatar answered Oct 15 '22 18:10

sasuri