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

将blobstore blob作为文件处理(python),python,google-app-engine,blobstore,Python,Google App Engine,Blobstore,我想使用GAE创建一个进程,在给定url的情况下,通过该进程下载文件并将其作为blobstore中的blob存储。完成后,我想将这个blob作为POST数据传递到第二个url。但是,要使第二部分正常工作,我需要能够将blob作为文件实例打开 我已经想出了如何做第一部分 from __future__ import with_statement from google.appengine.api import files imagefile = urllib2.urlopen('fileurl'

我想使用GAE创建一个进程,在给定url的情况下,通过该进程下载文件并将其作为blobstore中的blob存储。完成后,我想将这个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)
但我不知道如何做第二部分。到目前为止我已经试过了

  • ffile=files.open(files.blobstore.get\u file\u name(blob\u键),'r')

  • 来自google.appengine.ext import blobstore

    ffile = blobstore.BlobReader(blob_key)
    
    ffile = blobstore.BlobInfo.open(blobstore.BlobInfo(blob_key))
    
  • 来自google.appengine.ext import blobstore

    ffile = blobstore.BlobReader(blob_key)
    
    ffile = blobstore.BlobInfo.open(blobstore.BlobInfo(blob_key))
    
  • 对于
    isinstance(ffile,file)
    ,所有这些都给出了
    False


    非常感谢您的帮助。

    ffile=blobstore.BlobReader(blob_键)有效。但是,返回的对象只有一个类似文件的接口;它不扩展文件类。因此,isinstance测试不起作用。尝试类似于
    if ffile和dir(ffile)中的“read”(读取)

    从blobstore读取文件数据:

    blob_key = .....                                        # is what you have
    file_name = blobstore.BlobInfo.get(blob_key).filename   # the name of the file (image) to send 
    blob_reader = blobstore.BlobReader(blob_key)
    file_data = blob_reader.read()                          # and the file data with the image
    
    但您也可以使用blob_键发送url并提供url。对于图像,您不必自己为图像提供服务,因为您可以发布一个get_service_url,利用谷歌高性能图像服务API进行动态缩放。以这种方式提供图像也非常便宜

    以下是此类url的示例:


    谢谢。这可能意味着阻止我传递文件的错误正在更下游发生。谢谢。因为我需要将文件作为http POST传递,所以我认为我不能使用服务url。我现在可以使用blob_reader.read()读取图像数据。我仍然无法通过将blob_阅读器或文件数据传递到第二个网页使整个程序正常工作,因此我认为错误在更下游。由于我的错误似乎发生在更下游的地方,我已在上发布了一个扩展问题。我认为,由于这涉及到MW api的额外复杂性,因此最好将其视为一个新的post。