我正在将图像转换为Base64并将它们发送到websocket。
使用javacript:
var reader = new FileReader();
reader.onload = (function(aImg){
return function(e){
aImg.src = e.target.result;
imageMessage = aImg.src;
};
}(image))
var ret = reader.readAsDataURL(file);
在套接字服务器中,我得到字符串:
数据:图像/ JPEG; BASE64,/ 9J / 4AAQSkZJRgABAQEAYABgAAD / 4RFGRXhpZgAATU0AKgAAAAgACAEyAAIAAAAUAAAIegE7AAIAAAAHAAAIjkdGAAMAAAABAAMAAEdJAAMAAAABADIAAIKYAAIAAAAhAAAIlodpAAQAAAABAAAIuJydAAEAAAAOAAARMOocAAcAAAgMAAAAbgAAAAAc6gAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ......
因此,只要图像尺寸更大,字符串就会更长。 套接字崩溃了。
我的问题是如何将图像转换为小而简单的字符串。