【问题标题】:unsafe:data:image/*;base64,:1 GET unsafe:data:image/*;base64, (Javascript/Angular)unsafe:data:image/*;base64,:1 GET unsafe:data:image/*;base64, (Javascript/Angular)
【发布时间】:2018-05-16 15:43:01
【问题描述】:

我从我的 Spring Boot 应用程序中获得了 json 中 String64 格式的图像。

html

 <img id="userImage" src="{{ userImage }}"/>

打字稿

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);
    });
  }
}

错误:

core.js:7909 警告:清理不安全的 URL 值 SafeValue 必须使用 [property]=binding: data:Image/*;base64,/9j/4....

unsafe:data:image/*;base64,:1 GET unsafe:data:image/*;base64,

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    试试这个:

    <img id="userImage" [src]="userImage"/>
    

    如果仍有问题,请确保您从后端获取的图像是正确的图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2021-09-25
      相关资源
      最近更新 更多