miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.35k stars 672 forks source link

FilePicker on Web: Null bytes for Files Selected from OneDrive Folder #1631

Open Turskyi opened 3 days ago

Turskyi commented 3 days ago

Issue Summary When using the file_picker package on the Web platform, selecting an image from a OneDrive folder results in a FilePickerResult containing a PlatformFile object with bytes set to null. This makes it impossible to access the content of the selected file for further use, such as displaying the image.

Steps to Reproduce Use the FilePicker.platform.pickFiles method on the web platform (e.g., Chrome). Select an image from the OneDrive folder. Observe that the returned PlatformFile contains metadata (name, size) but has bytes and readStream as null. Sample Code:

final result = await FilePicker.platform.pickFiles(
allowMultiple: false,
        type: FileType.custom,
        allowedExtensions: 
            <String>[
              'jpg',
              'png',
            ],
);  
if (result != null) {  
  print(result.files.first.bytes); // Outputs: null  
} 

Observed Behavior The PlatformFile object returned has the following structure: PlatformFile(name: logo.png, bytes: null, readStream: null, size: 388400) Both bytes and readStream are null, making it impossible to use the file's content. Expected Behavior The PlatformFile.bytes field should contain the file's content as a byte array when selecting a file from the OneDrive folder, as it does for other folders.

Additional Details

Issue persists on both 8.0.0+1 and the latest version, 8.1.4.

Tested on Chrome browser on both MacOS and Windows platforms.

  1. Adding withData: kIsWeb to the pickFiles call did not resolve the issue.
  2. Testing in Example Project: Cloned the example project from GitHub repository. Added the following code to reveal the issue clearly:
    return ListTile(  
    title: Text(name),  
    subtitle: Text(path ?? 'bytes: ${_paths?.firstOrNull?.bytes}'),  // <<< added this, because on web `path` is null.
    );  

    Confirmed that the bytes field is null for files selected from the OneDrive folder. Notes The README shows an example for Windows where files from OneDrive are selected successfully, suggesting this behavior is unexpected.

https://github.com/user-attachments/assets/2360835a-0bf2-4345-bb6f-b8e0e5034917