【问题标题】:How to ensure Blob metadata is kept when copying blob in Python App Engine在 Python App Engine 中复制 blob 时如何确保保留 Blob 元数据
【发布时间】:2012-10-22 10:41:52
【问题描述】:

我正在将图像文件上传到服务器并调整其大小以节省数据存储中的磁盘空间。我调整大小然后删除原始 blob 并仅保留 blob 的 smallVersion 的方法会删除所有元数据。有没有办法从原始 blob 中复制 Blob 元数据并将其添加到新的较小版本中?

def post(self):
    upload_files = self.get_uploads('file')
    blob_info = upload_files[0]
    if blob_info:
        img = images.Image(blob_key=blob_info)
        img.im_feeling_lucky()
        img.resize(width=600, height=800)
        smallVersion = img.execute_transforms(output_encoding=images.JPEG)
        file_name = files.blobstore.create(mime_type='image/jpeg')
        with files.open(file_name, 'a') as f:  
            f.write(smallVersion)
        files.finalize(file_name)
        blob_key = files.blobstore.get_blob_key(file_name)
        blobstore.delete(blob_info.key())
        blobCacheURL = images.get_serving_url(blob_key)

【问题讨论】:

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


    【解决方案1】:

    当您使用 Files API 创建 blob 时,您可以设置上传的文件名:

    file_name = files.blobstore.create(mime_type='image/png',_blobinfo_uploaded_filename=file_name_from_url)
    

    我不知道在写入文件时可以设置的其他 blob 属性。您是否在寻找 mime_type 之外的其他属性?

    【讨论】:

    猜你喜欢
    • 2014-10-21
    • 2015-07-16
    • 2011-10-10
    • 2017-06-28
    • 2012-07-18
    • 2017-03-08
    • 2019-12-03
    • 2020-11-02
    • 1970-01-01
    相关资源
    最近更新 更多