【发布时间】:2014-02-17 16:29:25
【问题描述】:
我有一个博客,我希望用户能够上传图片。我怎样才能做到这一点。我的博客是用 Python、Jinja2 和谷歌应用引擎用 HTML 制作的。
谢谢你, 利亚姆
【问题讨论】:
标签: python html google-app-engine file-upload image-uploading
我有一个博客,我希望用户能够上传图片。我怎样才能做到这一点。我的博客是用 Python、Jinja2 和谷歌应用引擎用 HTML 制作的。
谢谢你, 利亚姆
【问题讨论】:
标签: python html google-app-engine file-upload image-uploading
对于上传,您可以使用 blobstore:请参阅文档:https://developers.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob
来自 blobstore 的图像可以由 Google 提供,使用:get_serving_url: https://developers.google.com/appengine/docs/python/images/
【讨论】:
是的,您可以在用户模型和图像模型之间使用 blobstore 和引用,例如:
class Image(db.Model):
reference = db.ReferenceProperty(User,
collection_name='matched_images', verbose_name='Title')
primary_image = blobstore.BlobReferenceProperty()
...如果您愿意,可以添加更多字段。然后通过 HTTP 帖子处理您的文件/图像上传:
class Upload(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
#... do form upload stuff and then get all uploaded images
for upload in self.get_uploads():
try:
img = Image(reference=user)
img.primary_image = upload.key()
img.put()
except:
pass
【讨论】:
您可以使用 blobstore。 https://developers.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob
祝你好运。
【讨论】: