对于下载,您只需要生成一个响应,其中包含标头“X-AppEngine-BlobKey:[your blob_key]”以及您需要的所有其他内容,例如 Content-Disposition 标头(如果需要)。或者如果它是一个图像,你可能应该只使用高性能图像服务 api,生成一个 url 并重定向到它....完成
对于上传,除了为 appengine 编写一个处理程序以在上传安全到 blobstore 后调用(在文档中)
您需要一种在传入请求中查找 blob 信息的方法。我不知道瓶子里的请求是什么样的。Blobstoreuploadhandler 有一个 get_uploads 方法,据我所知,它确实没有理由需要是一个实例方法。因此,这是一个需要 webob 请求的通用实现示例。对于瓶子,您需要编写与瓶子请求对象兼容的类似内容。
def get_uploads(request, field_name=None):
"""Get uploads for this request.
Args:
field_name: Only select uploads that were sent as a specific field.
populate_post: Add the non blob fields to request.POST
Returns:
A list of BlobInfo records corresponding to each upload.
Empty list if there are no blob-info records for field_name.
stolen from the SDK since they only provide a way to get to this
crap through their crappy webapp framework
"""
if not getattr(request, "__uploads", None):
request.__uploads = {}
for key, value in request.params.items():
if isinstance(value, cgi.FieldStorage):
if 'blob-key' in value.type_options:
request.__uploads.setdefault(key, []).append(
blobstore.parse_blob_info(value))
if field_name:
try:
return list(request.__uploads[field_name])
except KeyError:
return []
else:
results = []
for uploads in request.__uploads.itervalues():
results += uploads
return results