bogen
bogen

Reputation: 10432

How to ensure Blob metadata is kept when copying blob in Python App Engine

I am uploading a image file to the server and resizing it to save disk space in the datastore. My method of resizing and then deleting the original blob and only keeping the smallVersion of the blob removes all metadata. Is there a way to copy the Blob metadata from the original blob and add it to the new smaller version?

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)

Upvotes: 0

Views: 134

Answers (1)

voscausa
voscausa

Reputation: 11706

When you create the blob with the Files API, you can set the uploaded filename :

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

I'am not aware of other blob properties you can set, when writing a file. Are you looking for other properties beside the mime_type?

Upvotes: 1

Related Questions