Search code examples
flutterbytefilepicker

want to fetch bytes of selected file from device


So basically i want to select the files from my device and encrypt them with the help of bytes. I am done with the selection part and have done that using file picker if anyone can help me how to get bytes of the file i have selected it would be really helpful. here is my code to pick files from device


void selectFileFromDevice(d) async{
  FilePickerResult filePickerResult = await FilePicker.platform.pickFiles(allowMultiple: true);
  if(filePickerResult!=null){
    List<io.File> files = filePickerResult.paths.map((path) => io.File(path)).toList();
    
  }else{
    print('user cancelled the picker');
  }
}

the above code is working absolutely fine i just want to know how can get the bytes of my selected files. Thank you


Solution

  • you can use the following code to get the bytes of your file

    Uint8List  bytes = await  files[0].readAsBytes();