根据 App Engine Blobstore 的文档,对于 BlobStore 中的每个条目,DataStore 中都应该有一个 BlobInfo 条目。那为什么我的 blobInfo 在下面的代码中为空?
笔记:
- 如果我删除 BlobInfo 代码,则 servlet 会按原样返回资源(但没有文件名)
- 为简洁起见,我删除了异常和参数处理
我将非常感谢您的帮助。
public class GetResourceServlet extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
private BlobInfoFactory infoFactory = new BlobInfoFactory();
public void doGet ( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String blobKeyStr = request.getParameter("blob-key");
BlobKey blobKey = new BlobKey(blobKeyStr);
BlobInfo info = infoFactory.loadBlobInfo(blobKey); // returns null !?
String fname = info.getFilename();
response.addHeader("content-disposition", "attachment; filename=" + fname);
blobstoreService.serve(blobKey, response);
}