-2

How can we choose file from local system drives in Flutter web development . Not in App Please any one suggest me .

I am using like this I can able to choose file But how can i get the file path

enter image description here

  • Please provide more info to help and remember to post code snippet with error log as text not as screenshot. – Blasanka May 21 '20 at 11:00
  • Please check these two posts. [post1](https://stackoverflow.com/questions/58120098/how-to-get-the-file-selected/58121886#58121886), [post2](https://stackoverflow.com/questions/56252856/how-to-pick-files-and-images-for-upload-with-flutter-web). Hope this solves your issue. – Abhilash Chandran May 22 '20 at 17:32
  • Does this answer your question? [How to get the file selected](https://stackoverflow.com/questions/58120098/how-to-get-the-file-selected) – Abhilash Chandran May 22 '20 at 17:33

1 Answers1

0

You need to get the data and create a MediaInfo class for it

class MediaInfo{
  String fileName;
  String filePath;
}

Get File Path

Future<MediaInfo> convertFileGetNamePath({@required html.File file}) async {
  final Map<String, dynamic> infoData = {};
  final reader = html.FileReader();
  reader.readAsDataUrl(file);
  await reader.onLoad.first;
  final fileName = file.name;
  infoData.addAll({
    'name': fileName,
    'path': filePath,
  });

  MediaInfo webImageInfo = MediaInfo();
  webImageInfo.fileName = infoData['name'];
  webImageInfo.filePath = infoData['path'];
  return webImageInfo;

}

Implement it in your code

MediaInfo getInfo = await convertFileGetNamePath(file: imageFile);
fileName = getInfo.fileName;
Jackson Lee
  • 1,198
  • 4
  • 12