Flutter readAsBytesSync file read incomplete to encode base64

白昼怎懂夜的黑 提交于 2021-01-29 18:20:02

问题


  1. List item

I'm trying to send a JPG image (captured by ImagePicker in emulator) via HTTP POST with base64 encoding to an AWS REST API. But readAsBytesSync() operation only reads a (head) part of the image (I've tested it printing to the string as bytes) thus base64 can only encode that small part. What may be the reason, many thanks for your help in advance.

  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

来源:https://stackoverflow.com/questions/62572652/flutter-readasbytessync-file-read-incomplete-to-encode-base64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!