我使用java servlet和ektorp for couchdb)。我将图片添加到数据库,但我没有显示它。
AttachmentInputStream data = db.getAttachment("document_id","attachment_id");我通过这种方式获取附件。问题是我不知道如何在java servlet中显示这个获取的图像。
提前感谢。
发布于 2016-07-28 19:31:38
基本上,您需要获取HttpServletResponse的输出流并进行缓冲写入。
String contentType = "image/png";
AttachmentInputStream data = db.getAttachment("document_id","attachment_id");
response.setContentType(contentType);
response.setContentLength(longToInt(data.getContentLength()));
OutputStream out = response.getOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
while ((count = data.read(buffer)) >= 0) {
out.write(buffer, 0, count);
}
out.close();
data.close();从link复制!
https://stackoverflow.com/questions/36969742
复制相似问题