0

如何从应用程序引擎下载 blob?我想搜索一个特定的 blob,然后提供一个下载链接。我尝试的是:

<input type="text" name="search"> 
<input type="submit" value="SEARCH" > 
<a href="/mygaeproject1">download link</a>

其中 mygaeprojectServlet 文件的 url 模式为 mygaeproject1....,文件内容为:

public class ProjectServlet extends HttpServlet {

  private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); 

  public void doGet(HttpServletRequest req, HttpServletResponse resp) 
     throws IOException 
  {
    BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));      
    blobstoreService.serve(blobKey, resp);
    BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
    BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
    resp.setContentLength(new Long(blobInfo.getSize()).intValue()); 
    resp.setHeader("content-type", blobInfo.getContentType()); 
    resp.setHeader("content-disposition", "attachment; filename=" + 
            blobInfo.getFilename()); 
    blobstoreService.serve(blobKey, resp); 
  }
}
4

0 回答 0