I am trying to attach an image to an existing document on couchdb using python. It is attached, but the following error message appears: "Cannot be displayed because it contains an error". The length is also incorrect. Is the coding probably wrong? But how can it be done correctly?
If I attach it directly in Futon:
"_attachments": {
"Scan.png": {
"content_type": "image/png",
"revpos": 35,
"digest": "md5-t20y23eHOJOMDAwCcrTjOw==",
"length": 199281, // in python "length": 8
"stub": true
}
}
import couchdb
couch = couchdb.Server('http://a73657.berlin.de:5984')
db = couch['vl'] # existing
json_file = "test_file"
doc = db.get(json_file)
db.put_attachment(doc, 'Scan.png', 'Scan.png', content_type="image/png;base64")
According to the docs the
contentargument (the second arg) is "either a file-like object or a string", you've provided the second option, so the content of your attachment is the string "Scan.png" (hence the 8 char length).You're probably trying to use something more like this: