I am having a problem writing a file in Flutter. I keep getting this error:
FileSystemException: Cannot create file, path = '/data/local/tmp/temp.png' (OS Error: Permission denied, errno = 13)
For some reason, it's only happening on some devices. I can't seem to duplicate the problem myself, but people are reporting it to me.
Here's the basic code:
final Io.Directory systemTempDir = Io.Directory.systemTemp;
final Io.File file = await new Io.File('${systemTempDir.path}/temp.png').create();
file.writeAsBytes(finalImage);
final Io.Directory systemTempDir = Io.Directory.systemTemp;
seems to not work in release mode.
I had to do as below:
Directory tempDir = await getTemporaryDirectory();
final File file = File("${tempDir.path}/$fileName");
getTemporaryDirectory()
is provided by path_provider.
There may be a problem with the paths depending on the device being used. Have a look at the path_provider plugin: https://pub.dartlang.org/packages/path_provider
There's a good write-up of how to read and write files in the Flutter Cookbook on flutter.io: https://flutter.io/cookbook/persistence/reading-writing-files/
In Android Q, just add the Following Lines in AndroidManifest file:
<application
android:requestLegacyExternalStorage="true"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With