我正在尝试将图像字节转换为base64编码的字符串,此操作是成功的,但是当我打印出编码的字符串时,我得到了ff:
/9j/4RgvRXhpZgAASUkqAAgAAAANAAABBAABAAAAQAYAAAEBBAABAAAAsAQAAA8BAgAIAAAAqgAAABABAgAIAAAAsgAAABIBAwABAAAACAAAABoBBQABAAAAugAAABsBBQABAAAAwgAAACgBAwABAAAAAgAAADEBAgANAAAAygAAADIBAgAUAAAA2AAAABMCAwABAAAAAQAAAGmHBAABAAAA7AAAACWIBAABAAAA7gIAAAADAABzYW1zdW5nAFNNLVA1NTUASAAAAAEAAABIAAAAAQAAAFA1NTVYWFUxQ1JBMgAAMjAxOTowMToxNCAwOTozMzoyOAAZAJqCBQABAAAAHgIAAJ2CBQABAAAAJgIAACKIAwABAAAAAgAAACeIAwABAAAAZAAAAACQBwAEAAAAMDIyMAOQAgAUAAAALgIAAASQAgAUAAAAQgIAAAGRBwAEAAAAAQIDAAKSBQABAAAAVgIAAAWSBQABAAAAXgIAAAeSAwABAAAAAgAAAAiSAwABAAAAAAAAAAmSAwABAAAAAAAAAAqSBQABAAAAZgIAAHySBwBiAAAAbgIAAACgBwAEAAAAMDEwMAGgAwABAAAAAQAAAAKgBAABAAAAQAYAAAOgBAABAAAAsAQAAAWgBAABAAAA0AIAABeiAwABAAAAAgAAAAGjBwABAAAAAQAAAAKkAwABAAAAAAAAAAOkAwABAAAAAAAAAAakAwABAAAAAAAAAAAAAAABAAAAFAAAAPAAAABkAAAAMjAxOTowMToxNCAwOTozMzoyOAAyMDE5OjAxOjE0IDA5OjMzOjI4AP0AAABkAAAA/QAAAGQAAADrAAAAZAAAAAcAAQAHAAQAAAAwMTAwA
编码字符串应该比上面的字符更多。现在,当我尝试通过将data:image/jpeg;base64
附加到编码字符串的开头来查看此内容时,不会显示任何内容。
是颤动切割控制台中的字符串或什么,如果是,那么我如何获得完整的编码字符串。
如果您尝试将其发送到后端,则应将其转换为字节。这将为您提供您正在寻找的长字符串;)
var params = {
"image_file": base64Encode(_selectedImage.readAsBytesSync()),
};
How to native convert string -> base64 and base64 -> string展示了如何base64编码
Dart还在Uri
类上提供构造函数以获取数据URL
前者为您执行base64编码,后者使用已编码的字符串。