0

I have the below document which got synced from couchbase lite (iOS).

        {

        "Date": "00170925591601",
        "ID": "tmp652844",
        "InvoiceNumber": "tmp652844",
        "Supplier": "Temp",
        "_attachments": {
                        "ImageAttachment": {
                                            "content_type": "image/jpeg",
                                            "digest": "sha1-8uKi9mywFwvoP8qNrTGEMWemgKU=",
                                            "length": 1898952,
                                            "revpos": 2,
                                            "stub": true
                                            }
                        },
        "channels": [
                     "payment"
                    ],
        "type": "invoice"
       }

How do I get the attachment from the document? I need to render the image attachment in the HTML. I believe the above attachment data is only meta data. It would be of great help if someone can help me with this.

Thanks

2 Answers2

0

How do I get the attachment from the document? - this is a default dict with nested dicts and list inside it, you need a nested iterator function or a recursive method...

Community
  • 1
  • 1
Ari Gold
  • 1,528
  • 11
  • 18
  • I can iterate through the dictionary. That is not a problem. My question is how do I render the image in html? I'm using python SDK. – Kaushik Prakash Sep 20 '16 at 13:16
  • sry, but "How do I get the attachment from the document?" was the question for me...."webkit2png" would help you more http://stackoverflow.com/questions/5633828/html-to-image-in-python – Ari Gold Sep 20 '16 at 13:37
0

use the function ..

get_attachment(id_or_doc, filename, default=None) Return an attachment from the specified doc id and filename.

Parameters: id_or_doc – either a document ID or a dictionary or Document object representing the document that the attachment belongs to filename – the name of the attachment file default – default value to return when the document or attachment is not found Returns:
a file-like object with read and close methods, or the value of the default argument if the attachment is not found Since:
0.4.1

check https://pythonhosted.org/CouchDB/client.html#couchdb.client.Database.get_attachment for more details

Vaisakh Rajagopal
  • 1,189
  • 1
  • 14
  • 23