【问题标题】:GWT: how to attach GAE Blob data to new PDF fileGWT:如何将 GAE Blob 数据附加到新的 PDF 文件
【发布时间】:2015-02-13 05:10:36
【问题描述】:
我有一个存储在 GAE 服务器中的 PDF 文件,我想在客户端显示它。如何制作新的pdf文件?我尝试这样做:
String str = toBase64(result.get(1));// result.get(1) has byte[] type
HeadElement headElement = Document.get().createHeadElement();
LinkElement link = Document.get().createLinkElement();
link.setType("application/pdf");
link.setHref("Content-Disposition\", \"attachment;filename=" + str);
headElement.appendChild(link);
【问题讨论】:
标签:
google-app-engine
pdf
gwt
blob
【解决方案1】:
您无法在客户端上执行此操作。在客户端,您只需显示一个链接,如
https://myapp.com/file?id=123
如果您通过 id 存储 blob,或者您可以使用 blob 密钥等。在服务器端,您需要一个 servlet /file,它将获取此 id 或密钥,检索 blob,并设置正确的标头回应:
response.setHeader("Content-Disposition", "attachment;filename=" + "somename.pdf");
response.setContentType("application/pdf");
OutputStream outputStream = response.getOutputStream();
// document is byte[]
outputStream.write(document);
outputStream.close();
然后浏览器就会知道传入的响应是一个 PDF 文件。所以它会询问用户将其保存在哪里。