Reputation: 885
I want to save the image to my Download folder. I already add the permission but I still get the error like below.
I have add the permission in AndroidManifest.xml like these:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
I also have add android:requestLegacyExternalStorage="true" in AndroidManifest.xml
Beside that, I also have use the permission_handler: ^8.1.6 to open the storage permission.
_requestPermission() async {
Map<Permission, PermissionStatus> statuses = await [
Permission.storage,
].request();
final info = statuses[Permission.storage].toString();
print(info);
}
Here is the code for download the image. The package I use is downloads_path_provider: ^0.1.0
Future<File> downloadImage(Uint8List data, String name) async {
Directory tempDir = await DownloadsPathProvider.downloadsDirectory;
String tempPath = tempDir.path;
var filePath = tempPath + '/$name';
var bytes = ByteData.view(data.buffer);
final buffer = bytes.buffer;
return File(filePath).writeAsBytes(
buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
}
Here is the error when I want to download the image.
E/flutter (26950): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception:
FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/image-2021-09-23 17:18:47.923358.jpg'
(OS Error: Operation not permitted, errno = 1)
Does anyone know how to solve this error?
Upvotes: 2
Views: 5054
Reputation: 1650
For me the error was that the file name contained a colon ":", when removing it everything worked fine
Upvotes: 0
Reputation: 1408
I dont know how and whats the problem but i added the following lines in the AndroidManafist.xml files and it got fixed.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
Upvotes: 2