用户如何在网站上导入图片

时间:2014-01-26 23:23:23

标签: python html google-app-engine file-upload image-uploading

我有一个博客,我希望用户能够上传图片。我怎样才能做到这一点。我的博客是使用python,Jinja2和谷歌应用引擎的HTML制作的。

谢谢你, 利安

3 个答案:

答案 0 :(得分:1)

要上传,您可以使用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/

答案 1 :(得分:0)

是的,您可以使用用户模型和图像模型之间的blobstore和引用,例如:

class Image(db.Model): 
    reference = db.ReferenceProperty(User,
                                     collection_name='matched_images', verbose_name='Title')
    primary_image = blobstore.BlobReferenceProperty()

...如果你愿意,还有更多领域。然后通过HTTP post处理文件/图像上传:

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

答案 2 :(得分:0)