我已经在互联网上搜索并按照每个人所说的做,但由于某种原因,我无法将文件图像或其他文件保存到应用程序文件夹中。
我有这个方法来获取应用目录…
Future get _localAppPath async {
Directory? directory;
if (Platform.isAndroid) {
directory = await getApplicationDocumentsDirectory();
Utilities.logInfo('Local Android App Path is: ${directory.path}');
} else {
// if IOS Device
directory = await getTemporaryDirectory();
Utilities.logInfo('Local IOS App Path is: $directory');
}
return directory;
}
我在我的保存方法中使用它…
Future saveProfileImageLocally(File _file) async {
try {
final appDirPath = await _localAppPath;
//Utilities.logWarning('New path is: ${appDirPath.path}');
final fileExt = extension(_file.path);
// Check is directory exists
Utilities.logWarning('FilePath: ${_file.path}');
File newFile = await _file.rename('${appDirPath.path}/images/profileImage$fileExt');
Utilities.logWarning('New path is: ${newFile.path}');
Storage.saveValue('profileImage', newFile.path);
} catch (e) {
Utilities.logError(e.toString());
}
}
每次应用程序启动时我都会检查权限,所以我知道我有权限,但无论我不断收到此错误,没有这样的文件或目录…在阅读另一篇 stackoverflow 帖子之前,我一直在尝试使用复制功能。
FileSystemException: Cannot rename file to '/data/user/0/ca.company.example/app_flutter/images/profileImage.jpg', path = '/data/user/0/ca.company/example/cache/CAP370489784397780451.jpg' (OS Error: No such file or directory, errno = 2)
这应该是我在网上阅读的所有资源和教程中的一个简单的单行过程……所以我很困惑我错过了哪一步。
任何帮助将不胜感激。
© 版权声明
本站下载的源码均来自公开网络收集转发二次开发而来,
若侵犯了您的合法权益,请来信通知我们1413333033@qq.com,
我们会及时删除,给您带来的不便,我们深表歉意。
下载用户仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,访问及下载者下载默认同意本站声明的免责申明,请合理使用切勿商用。
THE END
暂无评论内容