- 项目清单
我正在尝试通过带有 base64 编码的 HTTP POST 将 JPG 图像(由模拟器中的 ImagePicker 捕获)发送到 AWS REST API。但是 readAsBytesSync() 操作只读取图像的(头部)部分(我已经测试过它以字节的形式打印到字符串中),因此 base64 只能编码那一小部分。可能是什么原因,非常感谢您提前提供的帮助。
Future<void> captureImage(ImageSource imageSource) async {
try {
ImagePicker picker = ImagePicker();
final pickedFile = await picker.getImage(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.front);
String theimagepath = pickedFile.path.toString();
//_imageFile = imageFile;
print('theimagepath just below');
print(theimagepath);
String img64 = base64Encode(Io.File(theimagepath).readAsBytesSync());
//print('bytes'+bytes.toString());
print('img64: '+img64);
_imageFile = Io.File(pickedFile.path);
setState(() {
print('State here is ');
------------- DEBUG OUTPUT BELOW (base64 encoded string is incomplete) -------------
I/flutter (13629): theimagepath just below
I/flutter (13629): /storage/emulated/0/Android/data/com.example.blabla/files/Pictures/f8a0295e-9ce5-446c-91d2-41c938e49b7f5430316734413263510.jpg
I/flutter (13629): img64: /9j/4QGqRXhpZgAATU0AKgAAAAgABwEQAAIAAAAPAAAAYgEAAAQAAAABAAAFoAEBAAQAAAABAAAHgAEyAAIAAAAUAAAAcQESAAMAAAABAAEAAIdpAAQAAAABAAAAjAEPAAIAAAAHAAAAhQAAAABzZGtfZ3Bob25lX3g4NgAyMDIwOjA2OjI1IDExOjUzOjU0AEdvb2dsZQAAEIKdAAUAAAABAAABUoKaAAUAAAABAAABWpKSAAIAAAAENDE2AJKRAAIAAAAENDE2AJKQAAIAAAAENDE2AJIKAAUAAAABAAABYpIJAAMAAAABAAAAAIgnAAMAAAABAGQAAJAEAAIAAAAUAAABapADAAIAAAAUAAABfqADAAQAAAABAAAHgKQDAAMAAAABAAAAAKACAAQAAAABAAAFoJICAAUAAAABAAABkpIBAAoAAAABAAABmpAAAAcAAAAEMDIyMAAAAAAAAACtAAAAZAAgCBc7msoAAAARHAAAA+gyMDIwOjA2OjI1IDExOjUzOjU0ADIwMjA6MDY6MjUgMTE6NTM6NTQAAAAAngAAAGQAACK/AAAD6P/gABBKRklGAAEBAAABAAEAAP/bAEMAAgEBAQEBAgEBAQICAgICBAMCAgICBQQEAwQGBQYGBgUGBgYHCQgGBwkHBgYICwgJCgoKCgoGCAsMCwoMCQoKCv/bAEMBAgICAgICBQMDBQoHBgcKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCv/AABEIB4AFoAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZ
I/flutter (13629): State here is