flutter_file_picker
flutter_file_picker copied to clipboard
Save-file dialog for Android and iOS ?
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
Meanwhile, I found the package "flutter_file_dialog" which do open a Save-file dialog for Android and iOS.
This issue is stale because it has been open for 14 days with no activity.
up
+1 for saveFile for Android
This issue is stale because it has been open for 14 days with no activity.
+1 Much required feature!
This issue is stale because it has been open for 14 days with no activity.
+1 Please implement this feature!
This issue is stale because it has been open for 14 days with no activity.
Why you don't react on this request?
This issue is stale because it has been open for 14 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
+1
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
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;
}
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);
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.
+1
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.
+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:
+1
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?
It's now supported in 7.1.0. Thanks!