2017-04-18 25 views
0

ジャージー・リラックス・サービスを使用して添付ファイルをダウンロードしたいと考えています。添付ファイルをダウンロードすることができません

以下

私のコードスニペットです:

Apr 18, 2017 12:06:23 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo 
SEVERE: MessageBodyWriter not found for media type=application/pdf, type=class org.glassfish.jersey.message.internal.OutboundJaxrsResponse, genericType=class org.glassfish.jersey.message.internal.OutboundJaxrsResponse. 
+0

詳細情報については、応答

return builder; 

を返すには、あなたの方法を投稿してくださいもらえますか?私が使用している注釈は、問題を診断する上で重要だと思います。 –

+0

質問タイトルを「添付ファイルをダウンロードできません」に変更してください。より多くの人々が正確にアクセスできます –

答えて

0

@Produces(MediaType.APPLICATION_OCTET_STREAM) 

にあなたのサブリソースメソッドに注釈を設定し、ファイルを作成します。

レスポンス以下のコードに戻り上記
if(entity != null) { 
    ResourceStream stream = new ResourceStream(entity); 
    return Response.ok(stream.getResponse(), entity.getMediatype()).header("Content-Disposition", "attachment; filename=\"" + entity.getName() + "\" ").build(); 
} 

オブジェクトのようなもの

File file = new File("Location of the file with file name"); 

この

if (file.exists()) { 
    ResponseBuilder builder = Response.ok(file); 
    builder.header("Content-Disposition", "attachment; filename=" + file.getName()); 
response = builder.build(); 

のような応答を送信し、

jersey file upload and download example

関連する問題