【发布时间】:2024-01-03 12:22:01
【问题描述】:
我正在尝试下载文件并将其保存在 Downlaod 目录中,但每次都收到此错误:
I/flutter (21400): FileSystemException: Cannot create file, path = '/storage/emulated/0/Download/contratto.jpg' (OS Error: File exists, errno = 17)
但是如果我在我的存储中搜索这个文件我没有找到它,我不明白。
在清单中我拥有所有权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
我正在使用 ext_storage 包来查找路径,但即使使用 path_provider 我也遇到了同样的错误。 这是我的代码:
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,
);
}
我正在使用 Flutter 2.0.6。 有什么想法吗?
编辑: 下载仅在我第一次保存具有特定名称的文件时有效,如果我删除它并尝试再次下载它,我会收到此错误。我也试过重新安装应用程序,但我仍然收到错误
【问题讨论】: