【问题标题】:cordova-plugin-file can't copy file from gallery to cordova.file.dataDirectorycordova-plugin-file 无法将文件从画廊复制到 cordova.file.dataDirectory
【发布时间】: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


    【解决方案1】:

    经过大量试验和错误后,我发现我需要为 Android 申请 READ_EXTERNAL_STORAGEWRITE_EXTERNAL_STORAGE 权限。

    以后我会检查 iOS 是否需要任何权限,但现在我很高兴它适用于 Android。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 2012-09-16
      • 2015-11-03
      • 1970-01-01
      相关资源
      最近更新 更多