【问题标题】:IONIC 3 filePath (native path) issue in case of PDF or DOC filesPDF 或 DOC 文件的 IONIC 3 filePath(本机路径)问题
【发布时间】:2018-07-16 06:32:59
【问题描述】:

我正在尝试使用 IONIC 3 的 fileChooser 插件选择 pdf 的 doc 文件,我得到这样的响应

content://com.coloros.filemanager/file_share/storage/emulated/0/documents/certificatenew.pdf

然后我尝试使用 IONIC 3 的 filePath 插件在 android 设备中获取本机路径,但我收到这样的错误

列“_data”不存在

我在 Android Naugat 和 Oreo 中遇到了这个问题。此外,使用相同的过程获取图像文件的本机路径,工作正常。

以下是部分代码,

.......

        this.fileChooser.open().then((url) => {

          this.filePath.resolveNativePath(url)
            .then(filePath => {

              let currentPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
              let currentName = filePath.split('/')[filePath.split('/').length - 1];
              let fileext = currentName.split(".").pop();
              var d = new Date(),
                n = d.getTime(),
                newFileName = n + '.' + fileext;

.......

谁能告诉我该怎么做?其背后的原因是什么?

【问题讨论】:

    标签: javascript android ionic3 angular5


    【解决方案1】:

    这段代码对我有用,

          this.fileChooser.open()
          .then(
            uri => {
              this.filePath.resolveNativePath(uri)
                .then(file => {
                  this.fileDir = file;
                  this.fileName = file.substring(file.lastIndexOf("/") + 1);
                })
                .catch(err => console.log(err));
            }
          )
          .catch(error => {
            this.showError(error);
          });
    

    【讨论】:

    • 感谢您的评论。但相同的错误列“_data”不存在实际上,我在 this.filePath.resolveNativePath(uri) 方法的 .catch err 部分收到错误。我认为这意味着文件路径插件在尝试从 Android 设备获取 pdf 或 doc 文件的本机路径时出错。正如我之前所说,这个错误只出现在牛轧糖和奥利奥版本中。以前的版本工作正常
    • 有人解决了吗?
    猜你喜欢
    • 2018-03-17
    • 1970-01-01
    • 2017-07-26
    • 2014-03-21
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 2019-02-15
    相关资源
    最近更新 更多