Sending a block or byte array in XML

I am a novice developer. I am developing a REST web service. My requirement is to send BLOB content from the server to the mobile side. My douubt, is it possible to send a BLOB to XML or should I convert it to ByteArray and send it?

+6
source share
1 answer

Primarily. Convert the bitmap to ByteArray, and then convert this byte array to the Base64 String format and send this Base64 String format to xml.

ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(CompressFormat.PNG, 0 , baos); //bmp is the bitmap object byte[] b = baos.toByteArray(); String encodedImage = Base64.encodeToString(b, Base64.DEFAULT); 

Now send the encodedImage to your xml ...

Convert Base64 to bitmap

 public static Bitmap convertByteArrayToBitmap(String Base64String) { byte[] data = Base64.decode(Base64String, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(data , 0, data.length); return bitmap; } 
+11
source

Source: https://habr.com/ru/post/915900/


All Articles