【发布时间】:2020-11-17 17:13:21
【问题描述】:
我正在尝试将摄像头中的视频记录保存到cordova.file.dataDirectory,但是当我尝试从图库中复制新创建的文件时,我得到了NOT_FOUND_ERR。
我正在使用cordova-plugin-media-capture 录制视频,然后将其保存到用户的图库中。但是当我使用window.resolveLocalFileSystemURL 得到FileEntry 并尝试使用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 cordova cordova-plugin-file