python - Google App Engine 上传图像 Blobstore

标签 python google-app-engine upload blobstore

我想让用户上传图像并为此上传制作演示,并阅读 GAE Blobstore API。

我的问题是,在提交图像文件时,出现错误 AttributeError: 'UploadHandlerDemo' object has no attribute 'get' but Blob class is已经在数据存储中创建。我该如何处理这个问题?

这是我的代码片段:

class FileUploadDemo(webapp2.RequestHandler):
    def get(self):
        from google.appengine.ext import blobstore
        upload_url = blobstore.create_upload_url('/admin/upload')
        logging.info(upload_url)
        blob = blobstore.BlobInfo.all().get()
        logging.info(blob.filename)
        content = {"upload_url":upload_url}
        HelperGlobal.render_template(self, 'blobstoreDemo.html', content)

这是我的 UploadHandler:

from google.appengine.ext.webapp import blobstore_handlers
class UploadHandlerDemo(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get.uploads('file')
        blob_info = upload_files[0]   
        logging.info(blob_info) 
        self.redirect('/admin/serve/%s' % blob_info.key())

在数据存储路径中,我有 BlobInfoBlobUplaodSessions,它们看起来不错。

在 html 部分,我将 GAE Blobstore 示例转换为单个 HTML,并在 JINJA 的帮助下使用 upload_url 数据呈现。

这里是我的简单演示的 HTML 代码:

<html>
<body>
<form action="{{upload_url}}" method="POST" enctype="multipart/form-data">
Upload File: <input type="file" name="file" id="UniqueFile">
             <br> 
             <input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

当我按下提交按钮时,它会创建具有相应图像的 BlobInfo 实体,但服务器收到错误代码 500,并显示:

AttributeError:“UploadHandlerDemo”对象没有属性“get”

我进行了多次尝试,看起来在 stackoverflow 上,但无法找到解决方案。

最佳答案

我认为:upload_files = self.get.uploads('file')

应该是: upload_files = self.get_uploads('文件')

关于python - Google App Engine 上传图像 Blobstore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27381484/

相关文章:

java - 使用android将图像上传到apache tomcat服务器

.net - 使用 ASP.NET : what are the best practices? 上传大文件

python - (PyQt 和 PySide)QFileDialog.getExistingDirectory 在 Windows 上不起作用

python - Django Rest 框架序列化器中有没有什么方法可以忽略选择字段中的大小写?

python - 尽管文件显示在存储桶中,但 Blobstore 上传的 get_uploads 返回空列表

google-app-engine - App Engine(Java)的体面备份工具?使用增量备份

使用 Google Apps Engine 时出现 Python 错误

iphone - 如何在 iOS 中使用图片上传代码发布更多参数?

python - 在Cloudera VM中阅读教程CSV文件时的异常(exception)

python - python 中的慢 for 循环