PouchDB Retrieve AttachmentThe getAttachment() method is used to retrieve an attachment from PouchDB. This method always returns blob or buffer objects. You have to pass the document id and attachment id to use this method. This method also accepts an optional callback function. Syntax: Retrieve Attachment ExampleLet's use getAttachment() method to retrieve an attachment attachment_1.txt from the document "002" from the database named "Last_Database". Save the above code in a file named "Read_Attachment.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Retrieve Attachment from a Remote DocumentYou can also retrieve an attachment from a remotely stored server (CouchDB). You just have to pass the path to the database in CouchDB, which contains the document that that you want to read. ExampleWe have a database name "employees" stored on the CouchDB server. Click on the "employees" database. You will see the documents within the database. You can see a document having id "001". Click on the id and you will find the attachment. You can see it by using Node.js command prompt: Save the above code in a file named "Read_Remote_Attachment.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Output: Next TopicPouchDB Delete Attachment |