问题
- 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