0

アプリエンジンからブロブをダウンロードするには?? 私は特定のブロブを検索し、ダウンロードリンクを提供したい..私が試したのは:

<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