flutter-form-builder-ecosystem / form_builder_file_picker

File picker field widget for FlutterFormBuilder.
https://pub.dev/packages/form_builder_file_picker
BSD 3-Clause "New" or "Revised" License
15 stars 33 forks source link

how can i load files as PlatformFile Type from file path and display them for edit purpose? #68

Closed saifonglee closed 1 year ago

saifonglee commented 1 year ago

how can i load files as PlatformFile Type from file path and display them for edit purpose?

i have a path like: https://mydomains.com/medias/files/file.pdf or https://mydomains.com/medias/files/image.png I've used form_builder_file_picker to upload multiple file to my server.

Now i have to load and display them for edit. I've tried to convert the file as below

List<PlatformFile>? document; _formatFile() async { PlatformFile? pfile; File file = File(filePath!); var bytes = await file.readAsBytes(); var name = file.path.split('/')[file.path.split('/').length - 1]; var size = bytes.length; pfile = PlatformFile(path: file.path, name: name, size: size); debugPrint(pfile.toString()); setState(() { document!.add(pfile!); }); }

this is the error that occurred: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PathNotFoundException: Cannot open file, path = 'https://mydomains/medias/files/apfr/299_APFR_BCST-50 manual-V23.pdf' (OS Error: No such file or directory, errno = 2) E/flutter (11435): #0 _checkForErrorResponse (dart:io/common.dart:55:9) E/flutter (11435): #1 _File.open.<anonymous closure> (dart:io/file_impl.dart:381:7)

it's about of this line: var bytes = await file.readAsBytes();

Is there an other way to do that?

_Originally posted by @saifonglee in https://github.com/flutter-form-builder-ecosystem/form_builder_file_picker/discussions/67_