I'm trying to download and save a file in the Downlaod directory, but every time I get this error:
I/flutter (21400): FileSystemException: Cannot create file, path = '/storage/emulated/0/Download/contratto.jpg' (OS Error: File exists, errno = 17)
But if I search this file in my storage I don't find it, I don't understand.
In the Manifest I've all the permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I'm using ext_storage package to find the path, but even with path_provider I got the same error. This is my code:
static Future download(String url, String fileName, String extension) async {
_checkPermission();
String _localPath = await ExtStorage.getExternalStoragePublicDirectory(
ExtStorage.DIRECTORY_DOWNLOADS);
Dio dio = Dio();
await dio.download(
url,
_localPath + "/" + fileName + "." + extension,
);
}
I'm using Flutter 2.0.6. Any ideas?
EDIT: The download works only the first time I save a file with a certain name, if I delete it and try to download it again I get this error. I've tried also to reinstall the app but I still get the error