2016-05-01 16 views
0

私はcouchdbにjava servletとektorpを使用しています)。画像をデータベースに追加しましたが、表示しませんでした。javaとektorpを使用した添付ファイルの取得

AttachmentInputStream data = db.getAttachment("document_id","attachment_id"); 

この方法で添付ファイルを取得しました。問題は、私はこのサーブレットをJavaサーブレットでどのように表示するかわかりません。

ありがとうございます。

答えて

-2

基本的には、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からコピーされました!

関連する問題