如何从app引擎下载blob?我想搜索特定的blob并提供下载链接..我试过的是:
<input type="text" name="search">
<input type="submit" value="SEARCH" >
<a href="/mygaeproject1">download link</a>
其中mygaeprojectServlet文件的网址格式为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);
}
}