Javascript Show base64 img给出的字符串包含无效字符

Javascript Show base64 img给出的字符串包含无效字符,javascript,ionic3,cordova-plugins,Javascript,Ionic3,Cordova Plugins,我正在尝试显示一个base64图像,这是我从相机插件(iOS,ionic 3)中获得的。我需要base64格式,因为我需要它用于RESTAPI调用。 启动拍照功能后,我得到 The String contains invalid characters 我在一个工具中解码了imageData字符串,它是有效的 JS image: string = ''; base64Image: string = ''; base64Data: string[] = []; _images: boolean =

我正在尝试显示一个base64图像,这是我从相机插件(iOS,ionic 3)中获得的。我需要base64格式,因为我需要它用于RESTAPI调用。 启动拍照功能后,我得到

The String contains invalid characters
我在一个工具中解码了imageData字符串,它是有效的

JS

image: string = '';
base64Image: string = '';
base64Data: string[] = [];
_images: boolean = false;
...

takePicture() {

        const options: CameraOptions = {
          quality: 100,
          destinationType: this.camera.DestinationType.DATA_URL,
          encodingType: this.camera.EncodingType.JPEG,
          mediaType: this.camera.MediaType.PICTURE,
          allowEdit: true,
          saveToPhotoAlbum: true,
          correctOrientation: true
        }

        this.camera.getPicture(options)
        .then((imageData) => {
         let base64Image = 'data:image/jpeg;base64,' + imageData;
         console.log(base64Image);
         this.base64Data.push(imageData);
         this.image = base64Image;
         this._images = true;
        }, (err) => {
         // Handle error
         console.log(`ERR -> ${JSON.stringify(err)}`);
        });
}
HTML

<div *ngIf="_images">
    <img [src]="image | safePipe: 'html'" #imageResult />
</div>

不确定什么是
imageData
,但为什么需要这种连接<代码>让base64Image='数据:image/jpeg;base64,“+imageData<代码>图像数据应该已经有标题。无论如何,从外观上看,您还必须对字符串进行编码:
let base64Image='btoa(data:image/jpeg;base64,“+imageData)
imageData没有包含头。它只是base64字符串。看见
...
public transform(value: string, type: string = 'html'): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
    switch (type) {
        case 'html': return this._sanitizer.bypassSecurityTrustHtml(value);
        case 'style': return this._sanitizer.bypassSecurityTrustStyle(value);
        case 'script': return this._sanitizer.bypassSecurityTrustScript(value);
        case 'url': return this._sanitizer.bypassSecurityTrustUrl(value);
        case 'resourceUrl': return this._sanitizer.bypassSecurityTrustResourceUrl(value);
        default: throw new Error(`Invalid safe type specified: ${type}`);
    }
}