Search code examples
javaandroidasp.netuploadksoap2

How to convert JPG file to binary string?


I wanna upload a jpg file from android to server using asp.net web service with ksoap2 library. I searched to net and found noting, Now i just can convert jpg file to binary and send string file and in server convert to jpg file

Somebody please help me.


Solution

  • You can use the Base64 Android class:

    String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
    Bitmap bm = BitmapFactory.decodeFile("/path/to/image.jpg");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object   
    byte[] b = baos.toByteArray();