[英]unsafe:data:image/*;base64,:1 GET unsafe:data:image/*;base64, (Javascript/Angular)
I get an image in String64 in json from my Spring Boot App. 我从Spring Boot App中以JSON中的String64获取图像。
html HTML
<img id="userImage" src="{{ userImage }}"/>
TypeScript 打字稿
import {Component, OnInit} from '@angular/core';
import {UserService} from "./services/user/user.service";
import {DomSanitizer} from "@angular/platform-browser";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
private user:any;
private userImage:any;
constructor(private userService:UserService, private sanitizer: DomSanitizer) {}
ngOnInit() {
//TODO hardcoded...
this.getUser("admin");
}
getUser(username) {
this.userService.getUser(username).subscribe(user => {
console.log(user);
this.user = user;
this.userImage = this.sanitizer.bypassSecurityTrustUrl("data:Image/*;base64," + user.image);
});
}
}
ERROR: 错误:
core.js:7909 WARNING: sanitizing unsafe URL value SafeValue must use [property]=binding: data:Image/*;base64,/9j/4....
core.js:7909警告:清理不安全的URL值SafeValue必须使用[property] = binding:data:Image / *; base64,/ 9j / 4 ....
unsafe:data:image/*;base64,:1 GET unsafe:data:image/*;base64,
Try this: 尝试这个:
<img id="userImage" [src]="userImage"/>
If you still have problems, please make sure the image you get from the backend is a proper image. 如果仍然有问题,请确保从后端获取的图像是正确的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.