Store images in datastore of GAE python while deploying web2py app

允我心安 提交于 2020-01-25 10:38:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!