python - 从 Google App Engine 上的 Blob_Info 获取 key 时出错

标签 python google-app-engine blobstore

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        reseller_id = self.request.get('reseller_id')
        upload_files = self.request.get('logo_img')
        if upload_files:
            blob_info = upload_files[0]
            key = blob_info.key()

我在线路中遇到错误

key = blob_info.key()

错误:

 AttributeError: 'str' object has no attribute 'key

问题是文件上传正确,我可以在 GAE blob 查看器中看到它。我从此处的上传示例复制了此代码:

https://developers.google.com/appengine/docs/python/blobstore/overview#Complete_Sample_App

我不知道为什么我没有通过使用 blob_info.key() 获取键值,欢迎任何指针。

最佳答案

请注意,在示例中它们执行以下操作:

upload_files = self.get_uploads('file')  # 'file' is file upload field in the form

在您的示例中,upload_files 是用户为 logo_img 字段设置的值,它是一个字符串。

我想 logo_img 字段是用户正在上传的文件,因此您需要这样做

upload_files = self.get_uploads('logo_img')

关于python - 从 Google App Engine 上的 Blob_Info 获取 key 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11147608/

相关文章:

python - 无法访问显示组件 - 从 Windows 服务调用

python - 如何更新模型

java - 在 GAE 中将名称设置为 blobstore

java - 在 Google App Engine 中存储旋转/翻转图像

python - 如何获取 google 自定义搜索 api 的开发者 ID?

java - 视频文件转换/转码 Google App Engine

python - Keras CNN 仅预测单个类别

python - 如何在igraph中查询与某个顶点相连的顶点?

python - 在 Python 中将文本文件读入列表

android - 在 Firebase 中读写数据