see on GitHub

Attachments: Loading Attachments

There are a few methods that allow you to download attachments from a database:

session.advanced.attachments.get() can be used to download an attachment.
session.advanced.attachments.getNames() can be used to download all attachment names that are attached to a document.
session.advanced.attachments.getRevision() can be used to download an attachment of a revision document.
session.advanced.attachments.exists() can be used to determine if an attachment exists on a document.

Syntax

session.advanced.attachments.getNames(entity);

session.advanced.attachments.exists(documentId, name);

session.advanced.attachments.get(documentId, name);

session.advanced.attachments.get(entity, name);

session.advanced.attachments.getRevision(documentId, name, changeVector);
Parameters
entity or documentId object or string instance of the entity or the entity ID
name string attachment name
changeVector string change vector for revision identification
Return Value
Promise<AttachmentStreamResult> Promise resolving to a Readable for attachment content

Example

const album = await session.load("albums/1");

const file1 = await session.advanced.attachments.get(album, "001.jpg");
const file2 = await session.advanced.attachments.get("albums/1", "002.jpg");

const inputStream = file1.data;

const attachmentDetails = file1.details;
//     { 
//       name: '001.jpg',
//       documentId: 'albums/1',
//       contentType: 'image/jpeg',
//       hash: 'MvUEcrFHSVDts5ZQv2bQ3r9RwtynqnyJzIbNYzu1ZXk=',
//       changeVector: '"A:3-K5TR36dafUC98AItzIa6ow"',
//       size: 25793 
//     }

const attachmentNames = await session.advanced.attachments.getNames(album);
for (const attachmentName of attachmentNames) {
    const name = attachmentName.name;
    const contentType = attachmentName.contentType;
    const hash = attachmentName.hash;
    const size = attachmentName.size;
}

const exists = session.advanced.attachments.exists("albums/1", "003.jpg");
// true