IONIC 3 IOS can't read data from file

谁说胖子不能爱 提交于 2019-12-04 03:51:43
let self = this;
self.filePicker.pickFile().then(uri => {

let correctPath = uri.substr(0, uri.lastIndexOf('/') + 1);
let currentName = uri.substring(uri.lastIndexOf('/') + 1);
self.file.readAsDataURL("file:///" + correctPath, currentName).then(result=>{                           


})

I have fixed this issue using this code.

I don't know much about the FilePicker you are using but why don't try with the Ionic native component to use the camera? Just give it a try to https://ionicframework.com/docs/native/camera/ it's really easy to use (there is an example in the link) I normally use it like this:

  public selectFromGallery() {
    var options: CameraOptions = {
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      destinationType: this.camera.DestinationType.FILE_URI,
      targetWidth: 640,
      targetHeight: 480,
      correctOrientation: true,
      quality: 100
    };
    this.camera.getPicture(options).then((imageData) => {
      return this.makeFileIntoBlob(imageData);
    }).then((imageBlob) => {
      this.cameraData = imageBlob;
      this.imageUpload(this.createFileName());
    }, (err) => {
      this.db.logMessage(new LogEntity("Error while selecting image", this.user.uid, JSON.stringify(err)), LogType.Error);
      this.presentToast(this.translations.code_image);
    });
  }

The getPicture method returns a promise which returns either a base64 string or a file URI. In my case I return an URI but just by changing the options destinationType to this.camera.DestinationType.DATA_URL you will get a base64 string and into the then statement: let base64Image = 'data:image/jpeg;base64,' + imageData;

Hope it helps you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!