开发者

Problem serving blobs in GAE

Im currently building an web-app that allows users to upload content via blobstore and to later download it.

However, the servlet that takes care of the download is called BlobServiceServlet and whenever a user downloads a blob, the filename is changed to "BlobServiceServlet" and the extension is also changed sometimes to .bin. 开发者_StackOverflow中文版Does anyone know how to fix this problem?


Add a "Content-disposition" header to the response.

See http://en.wikipedia.org/wiki/MIME#Content-Disposition for an example.

E.g., in the handler,

self.response.headers['Content-Disposition'] = 'attachment; filename=foo.doc'


Just an additional info. This is the code to let the browser know the file size:

BlobInfoFactory blobInfoFactory = new BlobInfoFactory(DatastoreServiceFactory.getDatastoreService());
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);

Note that if you have files with more than 1MB in size, the file size is not sent to browser. GAE reads the blob 1MB at a time and overwrites the file size header in the response.

I found all this information here: http://www.mail-archive.com/google-appengine@googlegroups.com/msg29314.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜