Javascript 离子3-下载一个文件到目录

Javascript 离子3-下载一个文件到目录,javascript,android,cordova,ionic-framework,ionic3,Javascript,Android,Cordova,Ionic Framework,Ionic3,我有类似的问题,比如: 下载后,我收到了成功警报,但在Android文件浏览器中,在成功下载后显示的路径下,我看不到该文件:file:///data/user/0/io.ionic.fileTest/image.jpg 我的代码: download(){ const fileTransfer: FileTransferObject = this.transfer.create(); const url = "http://cdna.allaboutvision.com/i/condition

我有类似的问题,比如:

下载后,我收到了成功警报,但在Android文件浏览器中,在成功下载后显示的路径下,我看不到该文件:file:///data/user/0/io.ionic.fileTest/image.jpg

我的代码:

download(){

const fileTransfer: FileTransferObject = this.transfer.create();
const url = "http://cdna.allaboutvision.com/i/conditions-2016/heterochromia-kate-bosworth-660x660-with-credit.jpg";

fileTransfer.download(url, this.file.dataDirectory + 'laska.jpg', true).then((entry) => {

  const alertSuccess = this.alertCtrl.create({
    title: `Download Succeeded!`,
    subTitle: `was successfully downloaded to: ${entry.toURL()}`,
    buttons: ['Ok']
  });
  alertSuccess.present();

}, (error) => {

  const alertFailure = this.alertCtrl.create({
    title: `Download Failed!`,
    subTitle: `was not successfully downloaded. Error code: ${error.code}`,
    buttons: ['Ok']
  });
  alertFailure.present();
});
}
我是否可以设法将此文件保存在“下载”文件夹或“文档”文件夹中?我还尝试将目标路径更改为:

cordova.file.externalRootDirectory + '/Download/'
在这种情况下,我收到了错误1

在许多例子中,我看到人们使用 window.requestFileSystem()
但是看起来窗口没有这个方法。我使用visual studio代码和爱奥尼亚3。

您在
文件传输中犯了一点小错误。请下载


使用将文件下载到下载目录的工作代码,而不是
this.file.applicationStorageDirectory
使用
this.file.dataDirectory

downloadFile() {
  this.fileTransfer.download("https://cdn.pixabay.com/photo/2017/01/06/23/21/soap-bubble-1959327_960_720.jpg", this.file.externalRootDirectory + 
  '/Download/' + "soap-bubble-1959327_960_720.jpg").then()
}

getPermission() {
  this.androidPermissions.hasPermission(this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE)
    .then(status => {
      if (status.hasPermission) {
        this.downloadFile();
      } 
      else {
        this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE)
          .then(status => {
            if(status.hasPermission) {
              this.downloadFile();
            }
          });
      }
    });
}

我也试过了。问题是,如果我使用dataDirectory,我得到的信息是dowload成功,但文件在android文件资源管理器中不可用。当我使用ApplicationStorage Directory时,收到错误消息1@bambaniasz如果您找到了解决方案,我们可以将文件存储在爱奥尼亚的下载文件夹中吗?@NarendraSinghRathore您需要先请求许可。@bambaniasz已经请求加载,但仍然无法存储它。