I'm developing an app in android which connects to a web service in php. The users can send pictures, or better said, will be able to send pictures cause I'm stuck on it, to other users.

Right now the image is sent to the web service via SOAP with type xsd:base64binary. The user take a picture and the byte array with data is converted to base64 before sending it in this way:

```
String img;
....
@Override
public void onPictureTaken(byte[] data, Camera camera) {
     img = Base64.encodeToString(data, Base64.NO_WRAP);         
}

```

In the server side, php stores img string in a mysql BLOB column.

When another user ask for the picture, the server retrieves the data from mysql in a stdClass, not only the image, also id, owner, etc... and encapsulate all this data into a JSON string with the php function json\_encode. The return type for this in the WSDL file is xsd:string. Back in Android what I do is:

```
JSONArray array = new JSONArray(response);
JSONObject row;
String imgStr;
byte[] img;

for (int i = 0; i < array.length(); i++) {
    row = array.getJSONObject(i);
    ...
    imgStr = row.getString("image");
    ...
}

if (!TextUtils.isEmpty(imgStr)) {
    img = Base64.decode(imgStr, Base64.NO_WRAP);
}

//Insert byte[] in android SQLite
dao.insert(id, owner, img);

```

The table column type in SQLite is BLOB as well. The problem comes up when I get the image from SQLite and try to convert it to Bitmap object. The code for this:

```
...
byte[] img = cursor.getBlob(cursor.getColumnIndex(DB.M_IMG));
Bitmap bmp = BitmapFactory.decodeByteArray(img, 0, img.length);
...

```

The img byte array seems to be alright but bmp is always null...

Some tests I've done are getting the base64 string on the image owner device before sending it and passing it to bitmap with good results, that's why I think my problem has something to do with encoding or addition of characters by json or php, I don't know...

UPDATE: If I hardcoded the base64 string from the mysql database, no bitmap is created, if I do the same with the base64 string generated in the moment I take the picture then it works.

What am I doing wrong?