Saturday, July 16, 2011

Android App Inventor - Load CSV File to Datastore

In a previous post I described how to use the TinyWebDB component within the Android App Inventor. This post described using the Google supplied TinyWebDB web service to store data on the web.

I was recently asked a question about how to pre-load the web service with data. Google provides a bulk-uploader service that you can use to load values from a file. After doing some research into the bulk-uploader it seemed to be very complex and I started to think of other ways to achieve a similar result.

The solution I created was using the web interface provided in the web service to upload a comma-separated file to the blobstore and subsequently loading the value into the datastore. I have attached the source code of this new version of the TinyWebDB web service to my source code page.

The main visible change to the application is the addition of a page to handle the uploads of the CSV files to the App Engine Blobstore. This uses a standard File Upload form control to display the File Open Dialog.

The page also displays the uploaded files along with an option to load the contents of the CSV file to the App Engine Datastore.


The main logic of the Blobstore Upload was courtesy of User: 010110110101 on StackOverflow who provided a great example of using Blobstore to store files in App Engine. I added this logic to the TinyWebDB web service code.

With the file uploaded to the blobstore, the web service then uses the Python CSV reader to read the file and load each key/value pair into the datastore. These key/value pairs are then available to the AppInventor application through the standard operations.

Feel free to use/modify this code for your own purposes. Enjoy.

My other App Inventor tutorials are:
App Inventor - Simple SMS
App Inventor - Location Services
App Inventor - Lists
App Inventor - TinyWebDB

Links
TinyWebDB Web Service
Blobstore Python Code - StackOverflow
CSV Reader in AppEngine - StackOverflow

3 comments:

  1. Hi Dave, this is a great post! I am quite new to python, and was hoping you can guide me a bit in regards to bulk importing data from CSV file and into our web app (Equella-digital repository) using python script and our web apps SOAP API?

    I can give you a further insight into what i mean, however, not sure if you would be able views this anytime soon?? if you do, please let me know and i will post a more detailed question.

    Look forward to hearing from you.

    best regards
    Amir

    ReplyDelete
  2. Your blog logic is really good.This is one of the developed post.I like your blog priority..
    Android app developers

    ReplyDelete
  3. Thanks for sharing your knowledge regarding android. It would really be of great help since most of the gadgets nowadays are run using Android OS.

    Keep sharing! :)

    Android App Creator

    ReplyDelete