我想要创建一个使用GAE的进程,在这个进程中,给定一个url,一个文件被下载并作为blob存储在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_file_name(blob_key), 'r')from google.appengine.ext import blobstore
ffile = blobstore.BlobReader(blob_key)from google.appengine.ext import blobstore
ffile = blobstore.BlobInfo.open(blobstore.BlobInfo(blob_key))所有这些都为False提供了isinstance(ffile, file)。
任何帮助都是非常感谢的。
发布于 2013-01-09 10:43:33
ffile = blobstore.BlobReader(blob_key)工作。但是,返回的对象只有一个类似文件的接口;它不扩展文件类。因此,isinstance测试不起作用。试试像if ffile and "read" in dir( ffile )这样的东西。
发布于 2013-01-09 14:23:15
要从from存储读取file_data:
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但是,您也可以发送一个url与blob_key和服务的网址。对于图像,您不必自己提供图像,因为您可以通过动态缩放使用发布一个get_serving_url。以这种方式提供图像也非常便宜。
下面是这样一个url的例子:
https://stackoverflow.com/questions/14233238
复制相似问题