Export blob properties from Datastore as binary files
Question: I store pictures as Blob properties in Datastore, I am not using Blobstore,
just Blob properties.

Now I want to migrate my app to a different platform and I'd like to get the
pictures out as JPEG files. Is there a way of doing this with the bulkloader
tool or using the mapper tool that appengine provides?

Thanks!

**Update**

I tried using the blob_to_file transform helper but could not make it work.

This is my bulkloader.yaml file

    
    
    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')
    

And this is my File model:

    
    
    class File(db.Model):
        fileId = db.IntegerProperty()
        bytes_content = db.BlobProperty()
    

I run the bulkloader with the following command:

    
    
    appcfg.py download_data --application=XXXX --kind=File --url=XXXXX/_ah/remote_api --filename=File.csv --config_file=bulkloader.yaml
    

At the end of download all I get is a big binary file and the folder pictures
is empty. Thanks for your help!


Answer: You can use the "Bulkloader Transform Helper function" blob_to_file(). General
information can be found at
<http://code.google.com/appengine/docs/python/tools/uploadingdata.html> and
Nick Johnson's write-up: <http://blog.notdot.net/2010/04/Using-the-new-
bulkloader>.

For BlobProperty export in particular, check out the bulkloader sample app:
<http://bulkloadersample.appspot.com/>

When you look at the 'bulkloader.yaml' file you will find this:

    
    
    python_preamble:
    - import: google.appengine.ext.bulkload.transform
    

and this:

    
    
    # 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')
    

