{"id":8104,"date":"2015-11-26T13:40:04","date_gmt":"2015-11-26T13:40:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/pouchdb-inline-attachment-saving-and-retrieving-open-source-projects-pouchdb-pouchdb\/"},"modified":"2022-08-30T15:03:01","modified_gmt":"2022-08-30T15:03:01","slug":"pouchdb-inline-attachment-saving-and-retrieving-open-source-projects-pouchdb-pouchdb","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/pouchdb-inline-attachment-saving-and-retrieving-open-source-projects-pouchdb-pouchdb\/","title":{"rendered":"pouchdb inline attachment &#8211; saving and retrieving-open source projects pouchdb\/pouchdb"},"content":{"rendered":"<p>I&#8217;m trying to use pouchdb to save an image which has been encoded in base64 format as an attachment against a document (inline) and then retrieve it again.<\/p>\n<p>However, when i retrieve the document it seems as though pouchdb has modified the base64 image data and has appended &#8216;md5-&#8216; to it. There is also no &#8216;data&#8217; attribute off of the attachment object, as i would have expected. Instead i find an object called &#8216;digest&#8217;. What is this?<\/p>\n<p>I have created an example:<\/p>\n<pre><code>var db = new PouchDB('example');\ndb.bulkDocs(\n    [\n      {\n        _id: '1', \n        name: 'example',\n        \"_attachments\": {\n            \"avatar.jpg\": {\n                \"content_type\": \"image\/jpg\",\n                \"data\": [BASE65 DATA STRING]\n        }\n      }\n    ], \n    function(err, response) {\n      if (!err) {\n        db.allDocs({ include_docs: true, attachments: true }, function(err, docs) {\n            var d  = docs.rows[0].doc;\n            \/\/ d looks like this: \n            \/\/ {\"name\":\"example\",\"_attachments\":{\"avatar.jpg\":{\"content_type\":\"image\/jpg\",\"digest\":\"md5-57e396baedfe1a034590339082b9abce\",\"stub\":true}},\"_id\":\"1\",\"_rev\":\"1-ff23a959ae88b871b94374a784a07728\"}\n        });\n      }\n    }\n);\n<\/code><\/pre>\n<p>Full example can be found here: http:\/\/jsfiddle.net\/ntan0ycL\/<\/p>\n<p>How would i go about retrieving the base64 representation of the image from the pouchdb document? I&#8217;m not sure if the problem lies in how i&#8217;m saving the attachment or how i&#8217;m retrieving it.<\/p>\n<p>Thanks,<\/p>\n<p>Andrew.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to use pouchdb to save an image which has been encoded in base64 format as an attachment against a document (inline) and then retrieve it again. However, when i retrieve the document it seems as though pouchdb has modified the base64 image data and has appended &#8216;md5-&#8216; to it. There is also no [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8104","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8104"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8104\/revisions"}],"predecessor-version":[{"id":8619,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8104\/revisions\/8619"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}