android - cordova-plugin-file 无法将文件从画廊复制到 cordova.file.dataDirectory
问题描述
我正在尝试将相机中的视频记录保存到,cordova.file.dataDirectory
但是NOT_FOUND_ERR
当我尝试从图库中复制新创建的文件时,我得到了一个。
我cordova-plugin-media-capture
用来录制视频,然后将其保存到用户的画廊。但是当我得到FileEntry
使用window.resolveLocalFileSystemURL
并尝试使用时entry.copyTo()
,NOT_FOUND_ERR
就会抛出错误。
我的代码的精简/混乱版本如下:
// Capture Video
navigator.device.capture.captureVideo(onCaptureSuccess, onError, { limit: 1 });
onCaptureSuccess(mediaFiles: any[]) {
// Get video Path
let videoPath = mediaFiles[0].fullPath;
// Get the actual video file
window.resolveLocalFileSystemURL(videoPath, entry => {
// Get the cordova.file.dataDirectory directory entry
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, directoryEntry => {
// Get / Create the 'videos' directory
directoryEntry.getDirectory('videos', { create: true }, videoDirectoryEntry => {
// Copy video file (entry) to 'videos' directory
entry.copyTo(videoDirectoryEntry, 'copiedVideo', copiedEntry => {
// I should now have a file entry of the copied video, but I don't. I get an error.
console.log(copiedEntry);
}, err => {
console.error(err); // This is where I capture the NOT_FOUND_ERR error
});
}, onError);
}, onError);
});
}
onError(error: Error) {
console.error(error.message)
}
知道为什么文件没有被复制吗?我是否需要请求特定权限才能写入cordova.file.dataDirectory
?
解决方案
经过大量的试验和错误,事实证明我需要为 Android 请求READ_EXTERNAL_STORAGE
和WRITE_EXTERNAL_STORAGE
权限。
在未来的某个日期,我会检查 iOS 是否需要任何权限,但现在我很高兴它适用于 Android。
推荐阅读
- java - 如何从另一个类更新按钮可见性?
- javascript - 我想从一个连续发送多行信息的脚本中实时获取所有回报
- php - Laravel 会话问题 - 覆盖现有会话密钥
- python - 带有 psycopg2 查询的 PostgresDB 成功执行,但有时更新记录,有时不更新
- xml - 使用 sed 连接 xml 标签
- react-native - 通过 API 获取 React JSX
- jenkins - 在 Jenkins 构建中生成 Allure 报告失败?
- c# - C# 从 PDF 中提取带有轴标签的图形图像
- javascript - 从输入生成 ID - Javascript 或 Jquery
- c# - 基于 FluentValidator 编写的自动生成文档