Java I';我试图将Base64中的一个映像转换为Blob,然后通过ServletOutputStream将其传递回,但它没有';行不通
如何将存储在数据库中的图像显示为base64代码、读取、转换为blob类型并将其作为ServletOutputStream发送回? 目前我只看到了一个黑暗的一面 我的HTML代码Java I';我试图将Base64中的一个映像转换为Blob,然后通过ServletOutputStream将其传递回,但它没有';行不通,java,Java,如何将存储在数据库中的图像显示为base64代码、读取、转换为blob类型并将其作为ServletOutputStream发送回? 目前我只看到了一个黑暗的一面 我的HTML代码 <img src= url + "/EinzelBild/1"> 到目前为止,我的结果是: @GetMapping(value = "/EinzelBild/{id}") @CrossOrigin public void f_pp_bild_s(HttpSer
<img src= url + "/EinzelBild/1">
到目前为止,我的结果是:
@GetMapping(value = "/EinzelBild/{id}")
@CrossOrigin
public void f_pp_bild_s(HttpServletResponse response, @PathVariable String id) throws IOException {
[...]
if (rs.next()) {
bild = rs.getBytes("projektbild_bin");
byte[] name = Base64.getEncoder().encode(bild);
Blob foto = new SerialBlob(name);
response.reset();
int length = (int) foto.length();
response.setHeader("Content-Length", String.valueOf(length));
response.setContentType("image/jpg");
InputStream in = foto.getBinaryStream();
final int bufferSize = 256;
byte[] buffer = new byte[bufferSize];
ServletOutputStream out = response.getOutputStream();
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
in.close();
out.flush();
foto = null;
}
}