4

Is there any way to store image files in firebase using Java api to be used for android application?

I have read this thread Can I store image files in firebase using Java API and still there is no answer. I know that there is an official api for it, called firepano here is the link https://github.com/firebase/firepano but it is for Javascript library.

is there any solution for Java library??

Community
  • 1
  • 1
sasuri
  • 972
  • 3
  • 11
  • 26
  • All the firepano library does is base64 encode the image and store it in a Firebase node. You can easily replicate that in Java. See http://stackoverflow.com/questions/13109588/base64-encoding-in-java – Frank van Puffelen Oct 24 '14 at 00:22

1 Answers1

12

I used this code and now it's working:

  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);     
sasuri
  • 972
  • 3
  • 11
  • 26
  • Sounds good. Don't forget to accept your answer (that will probably be allowed in a few days), so that it's clear that the question has been addressed (and to gain some reputation points). – Frank van Puffelen Oct 26 '14 at 13:33
  • @FrankvanPuffelen is It recommended though ? To upload images in Firebase ? Is it really meant to useful in that way ? Or direct upload on S3 bucket would be more preferable ? I use firebase for shopping list app, and I want to include image support. Thus asking! – shaktiman_droid May 08 '16 at 07:42