我有一个简单的休息服务,应该下载到png图像。
以下是代码:
@POST()
@Path(value= "/download")
@Produces( {"image/jpeg", "image/png", "image/bmp", "image/gif", "image/tiff"} )
@Consumes( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML} )
public Response downloadImage(ChatDownloadFileRequest input) {
ResponseBuilder response = null;
Image img = (Image)em2.createNamedQuery("Image.findByMessageId")
.setParameter("messageId", request.getMessageId())
.setHint("org.hibernate.cacheable", true)
.getSingleResult();
String imgPath = img.getPath();
File file = new File( imgPath );
response = Response.ok((Object)file);
String fileName = file.getName();
response.header("Content-Disposition", "attachment; filename=" + fileName);
return response.build();
}
当我拨打电话时,答案是204 No Content。
感谢所有
问候。