我已经设法使用Java服务器将文件保存在数据库中。现在,我想在Angular中显示MIME类型为image / jpg的文件。
问题是当我尝试发送GET请求时,我正确地收到了准确的图像。我不知道如何在html页面上显示它。 在下面,您可以看到我如何检索图像。
@GetMapping(path="/{id}", produces ="image/jpg")
public ResponseEntity<byte[]> getById(@PathVariable("id") Long id){
return new ResponseEntity<byte[]>(certService.getFile(id), HttpStatus.OK);
}
当我调用上述函数时,在解析http://localhost/certificate/131错误时,我也收到Http错误。
请问您如何在Angular上显示图像?
答案 0 :(得分:0)
您可以在img
标签上设置图像链接(http://localhost/certificate/131)
示例
<img src="http://localhost/certificate/131" />