简体   繁体   中英

Flutter file_picker is returning null bytes

I have the following code for file_picker. When I run it in a linux client, I get the following results. Is this a bug?

flutter: fatsquid.jpg
flutter: null
flutter: 497741
flutter: jpg
flutter: /home/mark/Pictures/fatsquid.jpg

I can't map form data from file.path as I am using flutter web.

FilePickerResult? result;
PlatformFile? file;

  selectFile() async {
    result = await FilePicker.platform.pickFiles(type: FileType.any);

    if (result != null) {
      file = result?.files.first;
    }

    print(file?.name);
    print(file?.bytes);
    print(file?.size);
    print(file?.extension);
    print(file?.path);

    setState(() {});
  }

file_picker: ^5.0.1

edit:

Applying the answer below, I get the following result.

flutter: fatsquid.jpg
flutter: 497741
flutter: 497741
flutter: jpg
flutter: /home/mark/Pictures/fatsquid.jpg

updated code:

result =
    await FilePicker.platform.pickFiles(type: FileType.any, withData: true);

you need to set

withData: true

if you want to have the file loaded into memory in advance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM