【问题标题】:Cordova-plugin-file Encoding_Err on AndroidAndroid 上的 Cordova-plugin-file Encoding_Err
【发布时间】:2019-08-23 12:59:58
【问题描述】:

我有一个 Ionic 3 应用程序,我可以在其中从设备上传图片。此功能在 IOS 上运行良好,但在 Android 上失败,错误代码为 5(编码错误)。

这是流程:

protected takePicture(source: number, callback: any) {
  const options: CameraOptions = {
    sourceType: source,
    mediaType: 2,
  };
  this.camera.getPicture(options).then((imageData) => {
    return callback(imageData)
  });
}

然后:

let promise = new Promise((resolve, reject) => {
    let prefix = '';
    if (i.indexOf('file://') === -1 && i !== '') {
      prefix = 'file://';
    }
    this.file.resolveLocalFilesystemUrl(prefix + i).then((fileEntry: any) => {
      fileEntry.file((file: any) => {
        let reader = new FileReader();
        if (file.size > 99999999) {
          return this.events.publish('error', this.errorUploadMessage, false);
        }
        reader.onloadend = function(e) {
          let blob = new Blob([this.result], { type: file.type });
          let filename = file.name;
          let extension = filename.match(/^.*\./);
          if (!extension || extension === '') {
            let type = file.type.split('/').pop();
            filename = filename + '.' + type;
          }
          resolve({ blob: blob, name: filename });
        };
        reader.readAsArrayBuffer(file);
      });
    }, (error) => {
      console.log(error);
      this.events.publish('error', this.errorUploadMessage, false);
    });
  });

在 IOS 上一切正常,所以我不明白为什么不能在 android 上运行。当我在这里检查路径时: this.file.resolveLocalFilesystemUrl(prefix + i)

我有这个: file://content://com.android.providers.media.documents/document/image%3A1313

也许问题出在最后的 'image%3A1313' 上。在IOS我可以看到真实的图片名称和扩展名(例如.jpeg)。

我已经检查了几个关于 SOF 的问题,但没有任何工作或似乎与我的问题相关。

【问题讨论】:

    标签: android cordova ionic-framework cordova-plugin-file


    【解决方案1】:

    好的,刚刚找到了解决方案...删除前缀(“file://”)似乎可以解决问题...这很奇怪,因为我从未在任何地方看到过此建议..

    【讨论】:

      猜你喜欢
      • 2019-01-05
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多