Downloading And Uploading Data on Google App Engine Using Java Application

We need to download data as a CSV from the app engine data store. This would help us get the data back from the app engine, just in case you want to move away or update from the data store.

We’ll go through a step by step example for using this tool with a Java application.

1. Download Google App Engine SDK for Python from here.
Unzip this file. Place it in your path. For Linux users.

export PATH

2. Now you have to set remote servlet with our Java application with which would be able to communicate with the app engine remotely. The following needs to be set up in your web.xml



Deploy your application to the app engine.

3. Now we are going to use to generate a configuration file: create_bulkloader_config --url= --application=APPID --filename=config.yml

Once you execute this command, after the necessary authentication the following file is generated

# Autogenerated bulkloader.yaml file.
# You must edit this file before using it. TODO: Remove this line when done.
# At a minimum address the items marked with TODO:
#  * Fill in connector and connector_options
#  * Review the property_map.
#    - Ensure the 'external_name' matches the name of your CSV column,
#      XML tag, etc.
#    - Check that __key__ property is what you want. Its value will become
#      the key name on import, and on export the value will be the Key
#      object.  If you would like automatic key generation on import and
#      omitting the key on export, you can remove the entire __key__
#      property from the property map.

# If you have module(s) with your model classes, add them here. Also
# change the kind properties to model_class.
- 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


- kind: Mobile
  connector: csv
  encoding: utf-8
    - property: __key__
      external_name: key
      export_transform: transform.key_id_or_name_as_string

    - property: model
      external_name: model
      # Type: String Stats: 1 properties of this type in this kind.

    - property: name
      external_name: name
      # Type: String Stats: 1 properties of this type in this kind.

    - property: timestamp
      external_name: timestamp
      # Type: Date/Time Stats: 1 properties of this type in this kind.
      import_transform: transform.import_date_time('%Y-%m-%dT%H:%M:%S')
      export_transform: transform.export_date_time('%Y-%m-%dT%H:%M:%S')

    - property: year
      external_name: year
      # Type: String Stats: 1 properties of this type in this kind.

4. It would create configuration for all entities. Replace these lines:

connector: # TODO: Choose a connector here: csv, simplexml, etc...
  # TODO: Add connector options here--these are specific to each connector.

with these

connector: csv
connector_options: encoding: utf-8

5. Now the next step is for downloading data. download_data --config_file=config.yml --filename=data.csv --kind=<kind> --url= --application=APPID

It will asked to provide email and password credentials.

To learn more, see .
Please enter login credentials for
Password for YOUR_EMAIL:
[INFO    ] Downloading kinds: ['kinds']
.[INFO    ] Greeting: No descending index on __key__, performing serial download
[INFO    ] Have 1 entities, 0 previously transferred
[INFO    ] 1 entities (11304 bytes) transferred in 10.5 seconds

There’s now a CSV file named data.csv in our directory, with autogenerated bulkloader files.
Open CSV file in text mode. You can make changes in CSV file by using text editor.

6. Now for uploading data. upload_data --config_file=config.yml --filename=data.csv --url= --application=APPID --kind=<kind>
To learn more, see .
Please enter login credentials for
Password for
[INFO    ] Starting import; maximum 10 entities per post
[INFO    ] 2 entites total, 0 previously transferred
[INFO    ] 2 entities (5394 bytes) transferred in 8.6 seconds
[INFO    ] All entities successfully transferred

The bulkloader took care of generating a mostly-finished configuration file for us, in a format that ensures the data we download can be re-uploaded again without loss of fidelity.

This entry was posted in Java, Web and tagged . Bookmark the permalink.

3 Responses to Downloading And Uploading Data on Google App Engine Using Java Application

  1. David Benque says:

    In case of permission error at step 3, have a look to that post:

  2. Pingback: GAE Java datastore bulk edit export import | 我爱源码网

  3. Is there anyway to download a selection of the data? eg like the GQL: “Select * from Contact where AdminID=1234”

    My previous downloads suggest that I have done this, but I cannot figure out how!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s