flutter_file_picker icon indicating copy to clipboard operation
flutter_file_picker copied to clipboard

Save-file dialog for Android and iOS ?

Open deacon78 opened this issue 4 years ago • 22 comments
trafficstars

Hello Miguel

Is it possible to have the api saveFile() for Android and iOS ?

Currently, it is not supported on Android and iOS by flutter_file_picker. cf https://github.com/miguelpruivo/flutter_file_picker/wiki/API#-savefile :

Platform Info
iOS Not supported
Android Not supported
Desktop Supported
Web Not supported

Why so ? I have read that an Android APP cannot write a file outside its directory. I have an app with local files (local db, etc.). I save files to application directory but my users would like to choose where to save files, and to save it on other locations like Download directory, GoogleDrive, Firebase, etc.

Is it possible or is it restricted by system iOS/ANDROID ?

Thank you

deacon78 avatar Nov 19 '21 08:11 deacon78

Meanwhile, I found the package "flutter_file_dialog" which do open a Save-file dialog for Android and iOS.

deacon78 avatar Nov 24 '21 07:11 deacon78

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Dec 02 '21 01:12 github-actions[bot]

up

deacon78 avatar Dec 02 '21 07:12 deacon78

+1 for saveFile for Android

4ntoine avatar Dec 10 '21 17:12 4ntoine

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Dec 22 '21 01:12 github-actions[bot]

+1 Much required feature!

syedecryptr avatar Dec 22 '21 09:12 syedecryptr

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Dec 31 '21 01:12 github-actions[bot]

+1 Please implement this feature!

yegor-pelykh avatar Dec 31 '21 11:12 yegor-pelykh

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Jan 09 '22 01:01 github-actions[bot]

Why you don't react on this request?

yegor-pelykh avatar Jan 09 '22 11:01 yegor-pelykh

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Jan 17 '22 01:01 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Feb 01 '22 01:02 github-actions[bot]

+1

selvam920 avatar Mar 02 '22 15:03 selvam920

We really need this. It seems like it shouldn't be too hard to implement. It's nearly the same as load file, the only thing it needs extra is to grab a filename string from the user

vanceism7 avatar Mar 18 '22 02:03 vanceism7

As a workaround, something you can do here is to use FilePicker.platform.getDirectoryPath (which does work on mobile platforms) to raise a dialog for selecting a directory, and then popup a SimpleDialog with a TextField prompting the user to enter a file name. It's a little more clunky than having it fully integrated into the OS, but its something

Example Code:

Future<String?> _getSaveFilenameMobile(BuildContext c) async {
    // Use getDirectoryPath to grab a directory from the mobile user
    final path = await FilePicker.platform.getDirectoryPath(
      dialogTitle: "Please select a file to save:",
    );
    if( path == null) return null;

    TextEditingController ctrl = TextEditingController();

    // Show a dialog to grab the filename from the user
    final outfile = await showDialog(
      context: c,
      builder: (c) => 
      SimpleDialog(
        title: const Text("File name"),
        children: [
          TextField(
            controller: ctrl,
          ),
          ElevatedButton(onPressed: () => Navigator.pop(c, ctrl.text), child: const Text("Ok")),
          OutlinedButton(onPressed: () => Navigator.pop(c, null), child: const Text("Cancel")),
        ],
      ),);

    //Check the result and return a file path
    if( outfile == null) return null;
    if( outfile.trim().isEmpty) return null;
    return path + "/" + outfile;
  }

vanceism7 avatar Mar 24 '22 21:03 vanceism7

The REAL workaround is to use "flutter_file_dialog" : https://pub.dev/packages/flutter_file_dialog

Just add these 3 lines in your code when you want to save a file "path_of_file_to_save" : final params = SaveFileDialogParams(sourceFilePath: "path_of_file_to_save");

final filePath = await FlutterFileDialog.saveFile(params: params);

print(filePath);

deacon78 avatar Mar 25 '22 07:03 deacon78

If anyone wants to save single and multiple files in android then give try my package pick_or_save which is heavily inspired by flutter_file_dialog.

With pick_or_save when saving multiple files you can allow users to choose a directory where you want files to be saved and for saving single files you can allow users to choose a location and file name.

Note: Currently when saving the file we are internally using the file name extension to determine the mime type and then letting the android put the extension after the file name automatically when saving the file. This tackles issues of saving a file with a name that already exists.

chaudharydeepanshu avatar Sep 19 '22 08:09 chaudharydeepanshu

+1

kimmy-wang avatar May 17 '23 02:05 kimmy-wang

I'd be happy to review and merge this feature if someone is willing to add it. But like someone mentioned, it should be easy to add a dependency to use along with this plugin and save the files, this way you keep the packages tighter and don't bloat it with features that can be easily added with another dependency when needed.

miguelpruivo avatar May 17 '23 10:05 miguelpruivo

+1 for this feature. There's a file_saver package which can handle file saving on most of the platforms, so the inspiration can be taken from there, or, if you don't want to bloat the plugin, maybe it's better to deprecate and remove the file saving functionality from it, leaving it up to other plugins? :thinking:

evgfilim1 avatar Nov 26 '23 11:11 evgfilim1

+1

bdesilvaA avatar Dec 04 '23 15:12 bdesilvaA

I would also like to see the functionality for saving in Android, iOS and Web in here. Thus far, Web is the only one for which I can't seem to find a workaround. I also am surprised that this functionality is missing, given that pick files works for all. Isn't it just basically the same file picker with another button and the ability to select nonexistent files?

KiraResari avatar Jan 27 '24 15:01 KiraResari

It's now supported in 7.1.0. Thanks!

miguelpruivo avatar Mar 20 '24 11:03 miguelpruivo