<small id='p1X8Y'></small><noframes id='p1X8Y'>

<i id='p1X8Y'><tr id='p1X8Y'><dt id='p1X8Y'><q id='p1X8Y'><span id='p1X8Y'><b id='p1X8Y'><form id='p1X8Y'><ins id='p1X8Y'></ins><ul id='p1X8Y'></ul><sub id='p1X8Y'></sub></form><legend id='p1X8Y'></legend><bdo id='p1X8Y'><pre id='p1X8Y'><center id='p1X8Y'></center></pre></bdo></b><th id='p1X8Y'></th></span></q></dt></tr></i><div id='p1X8Y'><tfoot id='p1X8Y'></tfoot><dl id='p1X8Y'><fieldset id='p1X8Y'></fieldset></dl></div>
    • <bdo id='p1X8Y'></bdo><ul id='p1X8Y'></ul>

      <tfoot id='p1X8Y'></tfoot>
      <legend id='p1X8Y'><style id='p1X8Y'><dir id='p1X8Y'><q id='p1X8Y'></q></dir></style></legend>

      1. 使用 Ionic 3 将文件保存到下载目录

        时间:2024-04-14

          <bdo id='LgH6R'></bdo><ul id='LgH6R'></ul>
            <tbody id='LgH6R'></tbody>
        • <legend id='LgH6R'><style id='LgH6R'><dir id='LgH6R'><q id='LgH6R'></q></dir></style></legend>

            <small id='LgH6R'></small><noframes id='LgH6R'>

          1. <i id='LgH6R'><tr id='LgH6R'><dt id='LgH6R'><q id='LgH6R'><span id='LgH6R'><b id='LgH6R'><form id='LgH6R'><ins id='LgH6R'></ins><ul id='LgH6R'></ul><sub id='LgH6R'></sub></form><legend id='LgH6R'></legend><bdo id='LgH6R'><pre id='LgH6R'><center id='LgH6R'></center></pre></bdo></b><th id='LgH6R'></th></span></q></dt></tr></i><div id='LgH6R'><tfoot id='LgH6R'></tfoot><dl id='LgH6R'><fieldset id='LgH6R'></fieldset></dl></div>

              • <tfoot id='LgH6R'></tfoot>
                  本文介绍了使用 Ionic 3 将文件保存到下载目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道这个链接:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files

                  但我想将文件保存在下载目录中.这是否可以使用 Ionic 将文件保存在任何路径中?如果是这样,请分享示例.

                  but i would like to save the file in Downloads directory. Is this possible to save the file in any path using Ionic? If so, please, share the example.

                  代码如下:

                  downloadImage(image) {
                  
                  this.platform.ready().then(() => {
                  
                    const fileTransfer: TransferObject = this.transfer.create();
                  
                    const imageLocation = `${cordova.file.applicationDirectory}www/assets/img/${image}`;
                  
                    fileTransfer.download(imageLocation, cordova.file.externalDataDirectory + image).then((entry) => {
                  
                      const alertSuccess = this.alertCtrl.create({
                        title: `Download Succeeded!`,
                        subTitle: `${image} was successfully downloaded to: ${entry.toURL()}`,
                        buttons: ['Ok']
                      });
                  
                      alertSuccess.present();
                  
                    }, (error) => {
                  
                      const alertFailure = this.alertCtrl.create({
                        title: `Download Failed!`,
                        subTitle: `${image} was not successfully downloaded. Error code: ${error.code}`,
                        buttons: ['Ok']
                      });
                  
                      alertFailure.present();
                  
                    });
                  
                  });
                  
                  }
                  

                  基本上我想将文件保存在用户可见的位置.

                  Basically I want save the file in location that is visible to the user.

                  推荐答案

                  问题是权限不足.这是可以将文件下载到下载目录的工作代码:

                  the problem was lack of permission. Here is the working code that can download file to downloads directory:

                  async downloadFile() {
                    await 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");
                  }
                  
                  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();
                              }
                            });
                        }
                      });
                  }
                  

                  这篇关于使用 Ionic 3 将文件保存到下载目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:IONIC 3 IOS 无法从文件中读取数据 下一篇:Android 上的 Ionic InAppBrowser 无法导航到自定义 URL 方案

                  相关文章

                  <tfoot id='FXMf8'></tfoot>
                    <bdo id='FXMf8'></bdo><ul id='FXMf8'></ul>

                  1. <i id='FXMf8'><tr id='FXMf8'><dt id='FXMf8'><q id='FXMf8'><span id='FXMf8'><b id='FXMf8'><form id='FXMf8'><ins id='FXMf8'></ins><ul id='FXMf8'></ul><sub id='FXMf8'></sub></form><legend id='FXMf8'></legend><bdo id='FXMf8'><pre id='FXMf8'><center id='FXMf8'></center></pre></bdo></b><th id='FXMf8'></th></span></q></dt></tr></i><div id='FXMf8'><tfoot id='FXMf8'></tfoot><dl id='FXMf8'><fieldset id='FXMf8'></fieldset></dl></div>

                    <small id='FXMf8'></small><noframes id='FXMf8'>

                      <legend id='FXMf8'><style id='FXMf8'><dir id='FXMf8'><q id='FXMf8'></q></dir></style></legend>