在浏览器中打开文档而不在服务器端生成文件

时间:2014-04-14 04:08:28

标签: google-app-engine

我将数据存储中的用户文档(ms word)存储为blob对象。 如何在浏览器中打开它?我可以将其下载,但我希望用户在下载之前在浏览器中查看该文档。我该怎么做?

我认为,为了能够通过设置响应头(内联和内容类型)在浏览器中打开文件,该文件应该实际存在于文件位置。 我没有空间来生成文件,然后写入浏览器。我该如何处理?

我可以将它们存储在谷歌硬盘中吗?是否会收取阅读和上传费用?任何指向示例的指针?

    daoIntf=new DAOImpl();
    document = daoIntf.getEntity("Document", id);
    Blob docBlob=(Blob)document.getProperty("resume");
    String fileName=(String)document.getProperty("fileName");
    String contentType=(String)document.getProperty("contentType");
    response.setContentType(contentType);   
    response.setHeader("Pragma" , "no-cache");   
    response.setHeader("Cache-Control" , "no-cache");   
    response.setDateHeader("Expires" , 0);       
    response.setHeader("Content-Disposition" , "inline;filename=\""+fileName+"\"");   
    ServletOutputStream out = response.getOutputStream();
    out.write(docBlob.getBytes());

-Thanks   马

2 个答案:

答案 0 :(得分:0)

如果Blobstore中有文档,则只需提供一个指向它的链接(即Java中的.getServingUrl())。当用户点击该链接时,他的浏览器将提供下载链接,或者如果该用户具有可以执行此操作的插件或扩展程序,它将以预览模式打开它。

答案 1 :(得分:0)

有一个在线Google文档查看器可以处理外部文档:https://docs.google.com/a/iddiction.com/viewer?pli=1

公开您的文档via servlet using blobstoreService.serve(key, response),然后在查看器中打开它们。

http://docs.google.com/viewer?url=<url_of_your_document>&embedded=<true|false>
相关问题