R
R
Romario212019-05-27 11:41:31
Java
Romario21, 2019-05-27 11:41:31

Android cut Base64 string?

Comrades, tell me what is the ambush?
Actually, you need to post json to the server, one of the fields of which is a photo in Base64.
The problem is that I'm only getting part of the picture in a Base64 string.
Image->Base64

public static String encodeTobase64(Bitmap image) {
    Bitmap immagex = image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.PNG, 100, baos);
    profileImage.setImageBitmap(Bitmap.createScaledBitmap(immagex, 120, 120, false));

    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(profileImage, Base64.DEFAULT);
    return imageEncoded;
}

Actually, at the output, I get only part of the photo in the Base64 string. If you reduce the resolution to 64x64. That's all right.
Another such moment, I received a Base64 string using an online converter. I tried to assign a value to String testBase64=".........", I received a message from the IDE saying that the size of the string is large, I can't assign it. The picture was ~500kb in jpeg format. This is also not clear, because theoretically, ~ 2,147,483,647 characters fit into a String.
The OutOfMemory program does not display

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-05-27
@Romario21

There is a limit on the length of a constant string - 64kb, if my memory serves me right.
The post needs to send a multipart entity, not json.
And so the conversion should work correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question