Rohit Barnwal Rohit Barnwal - 10 months ago 45
Python Question

migrating images to google app engine datastore or blobstore

I have property model, containing a field image_url.

class Property(ndb.Model):
# some other fields here
image_url = ndb.StringProperty(indexed=False)

and image model,

class Image(ndb.Model):
property = ndb.KeyProperty()
file = ndb.KeyProperty(indexed=False)
# some other fields
image_url = ndb.StringProperty(indexed=False)

Now I have 'n' number of images for each property in my local machine. Name of each image is mapped to corresponding property id in csv file. I want to bulk upload all these images from my local machine to google app engine datastore or blobstore.
I tried to google up but feel like I am stuck, any help or reference would be highly appreciated.

Answer Source

Google Cloud Storage might be a better option for you:

  • You get a nice program to work with it, gsutil, that will let you upload easily from the console, so you can write your own scripts :)

  • You can keep the filenames you already have, and setup your own directory structure so that it makes more sense for your app. If data is static then you might not even need support models.

Example, from the links above, on how you'd end up uploading your images:

gsutil cp *.jpg gs://images

The cp command behaves much like the Unix cp command with the recursion (-R) option, allowing you to copy whole directories or just the contents of directories. gsutil also supports wildcards, which makes it easy for you to copy or move batches of files.