您好,我的表中有spring boot应用程序,我将图像存储为字节[] arr。通过获取请求,我将结果发送到离子应用程序到显示器。但是在其中不显示图像。
这是代码,
@Column(name = "image")
public byte []getImage() {
return image;
}
public void setImage(byte [] image) {
this.image = image;
}
@GetMapping("/drivers/{id}")
public ResponseEntity<Drivers> getEmployeeById(@PathVariable(value = "id") Long driverId)
throws Exception {
Drivers employee = driverRepository.findById(driverId)
.orElseThrow(() -> new Exception("Employee not found for this id :: " + driverId));
return ResponseEntity.ok().body(employee);
}
etchAlarms(){
return this.http.get<any>('http://localhost:8080/api/getAllDrivers')
.subscribe(transformedData =>{
this.alarmsChanged.next(transformedData);
});
}
<img src="data:image/png;base64,{{alarms.image}}"/>
我读了几乎所有与此有关的问题,但不幸的是我无法解决问题。
这是我检查过的一些相关问题;
Ionic / AngularJS base64图像不会显示
这是Chrome控制台的错误
unsafe:data:image/png;base64,:1 GET unsafe:data:image/png;base64, net::ERR_UNKNOWN_URL_SCHEME
import { DomSanitizer } from '@angular/platform-browser';
constructor(public _DomSanitizationService: DomSanitizer)
将此添加到您的 Angular /离子
<img [src]="_DomSanitizationService.bypassSecurityTrustUrl('data:image/jpg;base64,'+alarms.image)"width="50%" height="50%" alt="Image"/>
将此行添加到您的HTML。
会的。