Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter file_picker is returning null bytes

Tags:

flutter

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);
like image 362
markhorrocks Avatar asked Feb 15 '26 21:02

markhorrocks


1 Answers

you need to set

withData: true

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

like image 100
Adil Shinwari Avatar answered Feb 18 '26 16:02

Adil Shinwari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!