ionic2 - 从库中选择后 base64 加载失败

ionic2 - base64 fails to load after selection from gallery

我正在使用可以正常工作的相机插件。我现在面临的问题是当我select图库中的图像或使用相机拍照时,图像无法显示在视图中

HTML

 <img *ngIf="base64Image"  [src]="base64Image" width="80" (click)="changePhoto()">

JAVASCRIPT

            let options = {
          quality: 90,
          allowEdit: true,
          targetWidth: 800,
          targetHeight: 800,
          destinationType: this.camera.DestinationType.DATA_URL,
          sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
          encodingType: this.camera.EncodingType.JPEG,
          mediaType: this.camera.MediaType.PICTURE
        };
        this.camera.getPicture(options).then((imageData) => {
          this.base64Image = "data:image/jpeg;base64," + imageData;
          this.hideMainPic='hide';
          //this.preLoaderImage.push(this.base64Image)


          const fileTransfer: FileTransferObject = this.Transfer.create();
          var options1 = {
            fileKey: 'file',
            fileName: 'name.jpg',
            headers: {}
          }
          fileTransfer.upload(imageData, 'http://apps.com/scripts/upload_photo.php', options1)
            .then((data) => {
              console.log(JSON.stringify(data));



            }, (err) => {
              let alert = this.alertCtrl.create({
                title: 'Error!',
                subTitle: 'Sorry, There was an error uploading photo',
                buttons: ['Try Again']
              });
              alert.present();
            });
        });

需要将目标类型添加到您的相机选项中,用这个替换您的选项

let options = {
  quality: 90,
  allowEdit: true,
  targetWidth: 800,
  targetHeight: 800,
  sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
};
 this.camera.getPicture(options).then((fileUri) => {
     this.base64Image = fileUri
 })