【问题标题】:Cordova File Plugin giving Security error on using readAsDataUrlCordova 文件插件在使用 readAsDataUrl 时出现安全错误
【发布时间】:2018-12-01 13:45:24
【问题描述】:

我正在使用 FileChooser 从我的手机内部存储中选择一个文件,并使用 File 插件将其转换为 base64,但 this.file.readAsDataUrl 给出错误“FileError{code:2, Message:SECURITY_ERR}"

我拥有所有必需的权限,但问题仍然存在,下面是我的代码

let base=this
  if(this.platform.is('android')){
    this.fileChooser.open()
    .then(uri => {

      var array = uri.split("/");

      var path=uri.substring(0, uri.lastIndexOf("/") + 1);

      console.log("path"+path)
      base.file.readAsDataURL(path, uri).then(dataText=>{
        console.log(dataText)
        var data = dataText;

      },(error)=>{
      console.log(error)
      })
    //console.log(uri)

    })
    .catch(e => console.log(e));
  }

我正在使用 Ionic 3、Angular4、Typescript、Firebase

【问题讨论】:

    标签: angular typescript ionic3 cordova-plugins ionic-native


    【解决方案1】:

    我遇到了同样的错误,我想知道这些错误总是在文件 URI 以 "content://" 开头时发生。 "file:///" 一切顺利。

    所以,我使用 Ionic (https://ionicframework.com/docs/native/file-path/) 的“文件路径”插件插入链接并将其转换为本地格式,该格式始终以 "file:///" 开头。

    在您的情况下,您需要在获取文件打开器的 URI 后直接调用 this.filePath.resolveNativePath(path) 以“翻译”它。

    【讨论】:

    • 这是解决问题的唯一方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多