我在加载 Base 64 格式的图像时遇到了一些问题。
在前端我有:
<img src="/path/to/rest/image">
其余服务代表:
@GET
@PublicResource
@Produces("image/*")
@Path("/path/to/rest/image")
public Response getResource() {
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(86400);
cacheControl.setPrivate(true);
//image.imputStream() is the stream of the image's base64 representation
Response.ok(image.getInputStream())).cacheControl(cacheControl)
.header("Cache-Control", "max-age=86400").build();
}
它返回正确的 base64,当我在任何解析器中将其解析为图像时,它会显示图像。但img标签仍然显示图像已损坏。 有什么想法如何解决它吗?也许我必须添加一些标题。
最佳答案
将以下文本添加到从休息服务返回的 Base 64 前面
data:image/png; base64,
关于java - 将base64中的图像从rest服务返回到img src标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39436951/