In the project, there is a feature similar to QQ's flash photo function. The logic for sending images is to first convert them to base64, then encrypt them, and finally send the encrypted string as a file. When processing the received images, the approach is to download the file first, then read the file content, decrypt it, and finally generate the image using the base64 string. However, this approach has been failing consistently.
Initially, it was thought to be an encryption/decryption issue. After careful investigation, this assumption was ruled out. Finally, when copying the decrypted string to VSCode for closer observation, it was noticed that there were many
\r\n characters present.
After searching, it was found that this issue was related to base64 encryption. Since base64 strings should not exceed 76 characters per line, if they do, a carriage return and line feed character will be added (in Windows it is
\r\n, in Linux it is
\n). The carriage return and line feed characters in the parsed string were causing the error. Therefore, the solution is to replace
\r\n with an empty string and then generate the image, which resolves the issue.