【发布时间】:2011-03-15 21:12:05
【问题描述】:
目前我在 Jersey 有一个方法,可以从内容存储库中检索文件并将其作为响应返回。该文件可以是 jpeg、gif、pdf、docx、html 等(基本上任何东西)。但是,目前,我无法弄清楚如何控制文件名,因为每个文件都会使用名称自动下载(下载。[文件扩展名],即(download.jpg,download.docx,download.pdf)。有没有办法让我可以设置文件名吗?我已经有它在一个字符串中,但我不知道如何设置响应,以便它显示该文件名而不是默认为“下载”。
@GET
@Path("/download/{id}")
public Response downloadContent(@PathParam("id") String id)
{
String serverUrl = "http://localhost:8080/alfresco/service/cmis";
String username = "admin";
String password = "admin";
Session session = getSession(serverUrl, username, password);
Document doc = (Document)session.getObject(session.createObjectId(id));
String filename = doc.getName();
ResponseBuilder rb = new ResponseBuilderImpl();
rb.type(doc.getContentStreamMimeType());
rb.entity(doc.getContentStream().getStream());
return rb.build();
}
【问题讨论】: