【问题标题】:How could users import pictures on website用户如何在网站上导入图片
【发布时间】:2014-02-17 16:29:25
【问题描述】:

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

谢谢你, 利亚姆

【问题讨论】:

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


    【解决方案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/

    【讨论】:

      【解决方案2】:

      是的,您可以在用户模型和图像模型之间使用 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
      

      【讨论】:

        【解决方案3】:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-01-23
          • 1970-01-01
          • 1970-01-01
          • 2011-02-06
          • 2020-11-08
          • 1970-01-01
          • 2011-04-28
          • 1970-01-01
          相关资源
          最近更新 更多