问题
I am trying to deploy a web2py application on GAE. When run locally, a phone_details table is defined in db.py using this line
db.define_table('phone_details',Field('image',type='upload'),Field('name',unique=True),Field('screensiz'),Field('primcam'),Field('processor'),Field('ram'),Field('rom'),Field('os'),Field('company'),Field('price','integer'))
To make it run on GAE, I created an entity in cloud datastore naming it 'phone_details' but there only string,boolean,number etc. are allowed datatypes i.e image is not allowed. How to upload image in a column of that table then. Do I need to use blobstore (searched from google, but I don't know how to use it and connect to my table defined in datastore) ?
回答1:
Rather than defining the entity yourself on GAE, you can instead enable migrations, and web2py will automatically create entities for your models (you can disable migrations after the initial request that will create the entities).
You will find that on GAE, web2py will define an additional blob field associated with each upload field. In your case, it will generate a field called image_blob
where the actual file will be stored (it will store the filename in the image
field, which is just a string field).
If you want to create the entity on your own, define the image
field as a string type, and create an image_blob
field.
来源:https://stackoverflow.com/questions/29543055/store-images-in-datastore-of-gae-python-while-deploying-web2py-app