skabir skabir - 6 months ago 168
Java Question

Can I store image files in firebase using Java API

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

Edit:
I got the solution. Converted the image to Base64 string and pushed to firebase.

Bitmap bmp = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
bmp.recycle();
byte[] byteArray = stream.toByteArray();
String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT);

Answer

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);