我将图片作为Blob属性存储在Datastore中,我不使用Blobstore,只使用Blob属性。
现在,我想把我的应用程序迁移到一个不同的平台,我想把图片作为JPEG文件输出。是否有一种方法可以使用大容量加载器工具或使用appengine提供的mapper工具?
谢谢!
更新
我试过使用blob_to_file转换助手,但无法使其工作。
这是我的bulkloader.yaml文件
python_preamble:
- import: base64
- import: re
- import: google.appengine.ext.bulkload.transform
- import: google.appengine.ext.bulkload.bulkloader_wizard
- import: google.appengine.ext.db
- import: google.appengine.api.datastore
- import: google.appengine.api.users
transformers:
- kind: File
connector: csv
connector_options:
encoding: utf-8
columns: from_header
property_map:
- property: fileId
external_name: fileId
- property: bytes_content
external_name: local_filename
export_transform: transform.blob_to_file('fileId', 'pictures')这是我的档案模型:
class File(db.Model):
fileId = db.IntegerProperty()
bytes_content = db.BlobProperty()我使用以下命令运行大容量加载程序:
appcfg.py download_data --application=XXXX --kind=File --url=XXXXX/_ah/remote_api --filename=File.csv --config_file=bulkloader.yaml下载结束时,我得到的只是一个大的二进制文件,文件夹图片是空的。谢谢你的帮忙!
发布于 2012-02-29 21:46:12
您可以使用"Bulkloader函数“blob_to_file()。一般信息可以在http://code.google.com/appengine/docs/python/tools/uploadingdata.html和尼克·约翰逊的文章“http://blog.notdot.net/2010/04/Using-the-new-bulkloader”上找到。
特别是对于BlobProperty导出,请查看大容量加载程序示例应用程序:http://bulkloadersample.appspot.com/
当您查看“bulkloader.yaml”文件时,您会发现以下内容:
python_preamble:
- import: google.appengine.ext.bulkload.transform这是:
# A sample writing a BlobProperty to an external file.
# (Note: not a BlobReferenceProperty.)
- model: models.Attachment
connector: csv
connector_options:
encoding: utf-8
columns: from_header
property_map:
- property: __key__
external_name: ID
export_transform: datastore.Key.name
- property: filename
external_name: filename
- property: filecontents
external_name: local_filename
export_transform:
transform.blob_to_file('filename', 'AttachmentBlobs')发布于 2012-03-02 02:39:19
您还有另外两种选择: 1)使用URL Fetch将数据发送到另一个系统;2)如果图像数量不多,可以逐个下载。我提取了一些工作代码作为示例:
kwis = KindWithImages.get_by_key_name(file_name)
if kwis:
(content_type, encoding) = mimetypes.guess_type(kwis.file_ext)
logging.info('download : %s%s content-type %s encoding %s' % (file_name, kwis.file_ext, content_type, encoding))
if content_type == None :
self.response.out.write('Content_type unknown for : %s' % (kwis.file_ext))
else :
self.response.headers['Content-Type'] = content_type
self.response.headers['Content-Disposition'] = 'attachment; filename=%s%s' % (file_name, kwis.file_ext)
self.response.out.write(kwis.content) https://stackoverflow.com/questions/9503600
复制相似问题