Why does a picture byte array have to be Base64 encoded before it can be transmitted?

the server gets the byte array corresponding to the picture. To transmit it to the android client through the http protocol, pass in the byte array of the picture with new String (), and then send it to the client. Then the client gets the byte array through the String.getBytes () method to parse the picture, so it must be encoded by Base64, and then the client side can decode it with Base64.

Mar.06,2021

The

http protocol can transfer binary data (pictures, video, and audio in the browser are all binary data). The problem is that the bytes must not be changed during transmission. It is generally not possible for you to directly convert the bytes of a picture into a string, unless the character set used has all corresponding characters between 0,255, otherwise it will cause some byte conversion errors, then the client will no longer receive those bytes.

base64 works because the encoded characters fall in the ASCII range, while ASCII is supported by all character encodings, so it can be transmitted and restored correctly.


The
http (s) protocol itself is not suitable for direct transmission of binary data, which is caused by the protocol itself.

therefore, the data must be converted into visible contiguous content, and Base64 can do just that.

Portal: pick the composition of HTTP

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4682a-44bbc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4682a-44bbc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?