python - 将 blobstore blob 作为文件处理 (python)

标签 python google-app-engine blobstore

我想使用 GAE 创建一个进程,根据给定的 url,下载文件并将其作为 blob 存储在 blobstore 中。完成此操作后,我想将此 blob 作为 POST 数据传递到第二个 url。但是,为了使第二部分正常工作,我需要能够将 blob 作为文件实例打开。

我已经弄清楚如何完成第一部分

from __future__ import with_statement
from google.appengine.api import files

imagefile = urllib2.urlopen('fileurl')
# Create the file
file_name = files.blobstore.create(mime_type=imagefile.headers['Content-Type'])
# Open the file and write to it
with files.open(file_name, 'ab') as f:
    f.write(imagefile.read())
# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)

但我不知道如何做第二部分。到目前为止我已经尝试过

  1. ffile = files.open(files.blobstore.get_file_name(blob_key), 'r')

  2. 从 google.appengine.ext 导入 blobstore

    ffile = blobstore.BlobReader(blob_key)
    
  3. 从 google.appengine.ext 导入 blobstore

    ffile = blobstore.BlobInfo.open(blobstore.BlobInfo(blob_key))
    

对于 isinstance(ffile, file),所有这些都给出 False

感谢任何帮助。

最佳答案

ffile = blobstore.BlobReader(blob_key) 有效。然而,返回的对象只有一个类似文件的接口(interface);它不扩展文件类。因此, isinstance 测试不起作用。尝试类似 if ffile and "read"in dir( ffile )

关于python - 将 blobstore blob 作为文件处理 (python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14233238/

相关文章:

python - 如何将 python 的谷歌云端点与现有的 GAE 项目集成?

internet-explorer - GAE 从 blobstore 下载文件扩展名

python - Pandas :groupby 和可变权重

python - 从交互式图表中抓取数据

python - 代码运行期间 Tkinter 标签更新

python - 导入错误 : No module named MySQLdb

php - 部署后如何在 Google App Engine Standard 上运行 Laravel 迁移

java - 是否可以使用gwt java开发离线aaplication

java - 在 Google App Engine 中存储旋转/翻转图像

google-app-engine - 我无法在 blobstore 中上传 2 次相同的图像