【问题标题】:Unable to download file from blobstore无法从 blobstore 下载文件
【发布时间】:2012-06-18 06:10:03
【问题描述】:


我已使用this 代码成功将文件上传到 blobstore。


但我无法下载
我正在做的是:

`class PartnerFileDownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self, blob_key):
    resource = str(urllib.unquote(blob_key))
    logging.info('I am here.')  //This gets printed successfully.
    blob_info = blobstore.BlobInfo.get(blob_key)
    logging.info(blob_info)   //This gets logged too. 
    self.send_blob(blob_info)`

我也试过:

blobstore.BlobReader(blob_key).read()

我以字符串形式获取文件数据,但我无法将其写入文件,因为我猜无法从处理程序中访问本地文件系统。

我上传文件的方式是我项目中唯一的方式,所以我不能使用谷歌官方教程中指定的常用方式。另外我上传到 blobstore 的文件不存在于我的本地文件系统中,我是从 URL 中选择的,也许这就是我无法下载文件的问题。
有什么建议吗?
谢谢

【问题讨论】:

    标签: google-app-engine python-2.7 blobstore


    【解决方案1】:

    也许您应该使用代码示例中的 resource 而不是 blob_key

    class PartnerFileDownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self, blob_key):
    resource = str(urllib.unquote(blob_key))
    self.send_blob(resource)
    

    【讨论】:

      【解决方案2】:

      您可以像这样使用 DownloadHandler:
      从 mimetypes 导入guess_type

          def mime_type(filename):
              return guess_type(filename)[0]
          class Thumbnailer(blobstore_handlers.BlobstoreDownloadHandler):
              def get(self , blob_key):
      
                  if blob_key:
                      blob_info = blobstore.get(blob_key)
      
      
                      if blob_info:
                          save_as1 =  blob_info.filename
                          mime_type=mime_type(blob_info.filename)
                          self.send_blob(blob_info,content_type=mime_type,save_as=save_as1)
      

      【讨论】:

        猜你喜欢
        • 2013-05-11
        • 2012-10-17
        • 1970-01-01
        • 2015-01-05
        • 2016-05-05
        • 2017-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多