Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending blob or byte array in XML

I am a novice back end developer. I am developing a REST webservice. My requirement is to send BLOB content from the server to Mobile Side. My douubt is, is it possible to send BLOB in XML or should I convert it into ByteArray and send it?

like image 445
varunrao321 Avatar asked May 16 '12 10:05

varunrao321


People also ask

Is Blob same as byte array?

Blob simply means (Binary Large Object) and its the way database stores byte array.

What is byte array?

A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..


1 Answers

First of all. Convert your Bitmap into ByteArray and then Convert that byte array to Base64 String format and send that Base64 String format in 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 encodedImage in your xml...

Base64 to bitmap conversion

public static Bitmap convertByteArrayToBitmap(String Base64String) 
{
    byte[] data = Base64.decode(Base64String, Base64.DEFAULT);
    Bitmap bitmap = BitmapFactory.decodeByteArray(data , 0, data.length);
    return bitmap;
}
like image 192
V.J. Avatar answered Oct 05 '22 02:10

V.J.