如何从GAE的blobstore下载具有原始文件名的文件? [英] How to download a file with its original filename from GAE's blobstore?

查看:136
本文介绍了如何从GAE的blobstore下载具有原始文件名的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将文件上传到blobstore后,它将其重命名为s9QmBqJPuiVzWbySYvHVRg ==。如果您导航到其/ serveURL来下载文件,则下载的文件将被命名为乱七八糟的字母。



有没有办法让下载的文件保留上传时它的原始文件名是什么? 使用 BlobUploadHandler
原始文件名作为名称属性存储在新创建的 BlobInfo 实体中。



blob服务处理程序,您可以指定blob应该作为下载附件返回,并且您可以指定使用何种名称保存

  from google.appengine.ext import webapp $ b $ import urllib 
$ b $ class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self,blob_info_key = None):
blob_info_key = str(urllib.unquote(blob_info_key))
blob_info = retrieve_blob_info(blob_info_key)
self.send_blob(blob_info,save_as = blob_info.filename)


blob_app = webapp.WSGIApplication([
('/ _s / blob /([^ /] +)',blob.ServeHandler),
],调试= config.DEBUG)


Once you upload a file to the blobstore, it renames it something like "s9QmBqJPuiVzWbySYvHVRg==". If you navigate to its "/serve" URL to download the file, the downloaded file is named this jumble of letters.

Is there a way to have the downloaded file retain its original filename when uploaded?

解决方案

When the file is uploaded using the BlobUploadHandler the original filename is stored as name property in the newly created BlobInfo entity.

In the blob serve handler, you can specify that the blob should be returned as download attachment, and you can specify with what name should it be saved with

from google.appengine.ext import webapp
import urllib

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, blob_info_key=None):
    blob_info_key = str(urllib.unquote(blob_info_key))
    blob_info = retrieve_blob_info(blob_info_key)
    self.send_blob(blob_info, save_as=blob_info.filename)


blob_app = webapp.WSGIApplication([
  ('/_s/blob/([^/]+)', blob.ServeHandler),
], debug=config.DEBUG)

这篇关于如何从GAE的blobstore下载具有原始文件名的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆