8

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?

1 Answer 1

13

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;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply BB Expert, I will try it.
BB Expert, can you help me with the reverse engineering?
yo! that worked, but the application is really slow, I am running netwrok connection, SAXParsing and DB insertion in a background thread..
You need to compress the image and then try to upload it. then it will work average fast.
sure, thanks for your reply, the abover requirement is for logo. On an average each logo is coming upto 20000 characters[]. Is this too huge?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.