Flutter_file_picker: Support for file paths on web

Created on 7 Mar 2021  路  6Comments  路  Source: miguelpruivo/flutter_file_picker

This plugin is apparently missing support for getting the file paths on web.

This is, however, supported by file_picker_cross.


We would love to use file_picker, however, this is not possible as we need the file paths to extract MIME types for example.

suggestion

Most helpful comment

I've checked the implementation and it should be quite easy to add it anyway. I'll add it later today if I have time. 馃憤

All 6 comments

@creativecreatorormaybenot this is a great addition since it is a missing part from web implementation.

If you are open to create a PR to add support to it (picking the same logic already implemented for all other platforms) it'll be great. Other than that, I may add it but I can't really tell you when.

I've checked the implementation and it should be quite easy to add it anyway. I'll add it later today if I have time. 馃憤

@miguelpruivo Thanks a lot 馃檹 Really looking forward to that 馃殌

@creativecreatorormaybenot sorry I misunderstood your OP. Looks like you want the paths, but browsers only delegate fake paths that can't be instanced anyway, hence the reason I removed it completely to not confuse developers.

How are you using the paths from file_picker_cross can you provide me an example?

Thank you.

@miguelpruivo As I tried to say above, only for the file name.

This allows both having semantics (because you keep the original file name the uploader chose) and also more importantly gives you access to the MIME type.

  final filePickerResult = await FilePickerCross.importFromStorage();

  final filePath = filePickerResult.path,
      originalName = p.basename(filePath),
      suffix = p.extension(filePath).toLowerCase(),
      data = filePickerResult.toUint8List(),
      type = mime(filePath),
      fileString = randomId + suffix;

  switch (suffix) {
    case '.svg':
      // ...
    case '.jpg':
    case '.png':
      // ...
  }

@creativecreatorormaybenot you still have access to mime types with file_picker. You don't need the path, neither you need it to extract the name. Actually, based on your snippet, you have much more effort with FilePickerCross to retrieve the data, than you have with the file_picker as it is. The PlatformFile object has all you need.

You just need to do like in the example:

   FilePickerResult result = FilePicker.platform.pickFiles();
   PlatformFile file = result.files.first;

   print(file.name);
   print(file.bytes);
   print(file.size);
   print(file.extension);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pushangupta picture pushangupta  路  6Comments

miguelpruivo picture miguelpruivo  路  7Comments

RAMSHEER picture RAMSHEER  路  6Comments

hauketoenjes picture hauketoenjes  路  6Comments

omuomugin picture omuomugin  路  4Comments