Cordova文件插件返回不存在的路径

时间:2017-06-21 13:19:05

标签: cordova

我想获取文件夹的路径,其中某些文件将从我的服务器下载。此代码如下所示:

// Get path to cache and download
window.resolveLocalFileSystemURL(cordova.file.externalCacheDirectory, entry => {
   console.log('download to', entry);
   // My download function
   fileDownload('some string url', entry.toUrl());
}, err => {
   console.log('error', err);
});

// Download function
function fileDownload(url, fileURL) {
  let fileTransfer = new FileTransfer();
  let uri = encodeURI(url);

  fileTransfer.download(
      uri,
      fileURL,
      entry => {
          console.log("download complete: " + entry.toURL());
      },
      error => {
         console.log("download error", error);
      },
      true
  );

  return fileTransfer;
}

如果config.xml包含行

<preference name="AndroidPersistentFileLocation" value="Internal"/>
<preference name="AndroidExtraFilesystems" value="files, cache, sdcard, cache-external, files-external"/> 

此竞赛错误FileError.code = 5(ENCODING_ERR)

如果使用Compatibility

<preference name="AndroidPersistentFileLocation" value="Compatibility"/>

这会返回条目路径file:///storage/emulated/0/Android/data/<my-app-id>/cache,但我的Nexus 5中不存在此路径,下载竞赛的代码错误1(FILE_NOT_FOUND_ERR)

FileTransferError {...}
body: null
code: 1
exception: "/storage/emulated/0/Android/data/<my-app-id>/cache: open failed: EISDIR (Is a directory)"
http_status: 200
source: "http://my.domain.com/photos/photo.jpg"
target: "file:///storage/emulated/0/Android/data/<my-app-id>/cache/"

我在ES文件管理器中看到正确的路径为/sdcard/Android/data/<my-app-id>/cache并认为问题就在于此。

任何想法如何获得正确的路径?

0 个答案:

没有答案