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/