我一直在尝试从Cloudant中的文档中获取附件图像数据。
一旦选择了文档(使用id直接提取,等等),我就可以成功地做到这一点。
现在尝试使用选择器将其与“查询”操作结合使用时,我遇到了麻烦。
这是我的密码。
targetName="chibika33"
targetfile="chibitest.png"
#--------------------------------------------------
# get all the documents with the specific nameField
#--------------------------------------------------
myDatabase.create_query_index(fields = ['nameField'])
selector = {'nameField': {'$eq': targetName}}
docs = myDatabase.get_query_result(selector)
#--------------------------------------------------
# get the attachment files to them, save it locally
#--------------------------------------------------
count = 0
for doc in docs:
count=count+1
result_filename="result%03d.png"%(count)
dataContent = doc.get_attachment(targetfile, attachment_type='binary')
dataContentb =base64.b64decode(dataContent)
with open(result_filename,'wb') as output:
output.write(dataContentb)
导致错误为;
Traceback (most recent call last):
File "view8.py", line 44, in <module>
dataContent = doc.get_attachment(targetfile, attachment_type='binary')
AttributeError: 'dict' object has no attribute 'get_attachment'
到目前为止,我在python cloudant文档中找不到任何用于将dict转换为document对象的API。。。[python cloudant文档]:
http://python-cloudant.readthedocs.io/en/latest/index.html
如有任何建议,我们将不胜感激。