Problem with decoding Base64 bitmap that sent to server via http request

Viewed 28

We are trying to call a post request via HTTP call in android, the library that we are using is Retrofit. First of all, we encode our Bitmap image to base64 with the following code.

public static String toBase64(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

    return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
}

And then we send our data using Retrofit to our server. Our backend is written both with Spring and Flask frameworks and both servers behave exactly the same.

We've tried to debug and find the problem. We found that some weird character is added to the request's body sometimes. It is not persistent but sometimes we got errors on server side. As you can see in the picture some characters are replaced with some weird characters that aren't in UTF-8 charset. Also, we have this issue on iOS platforms too and I should mention that the size of the image is around 1MB.

The 'Content-Type' header is set correctly like content-type: application/json; UTF-8.

I would really appreciate it if someone could help.

0 Answers
Related