Get Attachment Operation



Get attachment example

// Define the get attachment operation
const getAttachmentOp = new GetAttachmentOperation("employees/1-A", "attachmentName.txt", "Document", null);

// Execute the operation by passing it to operations.send
const attachmentResult = await documentStore.operations.send(getAttachmentOp);

// Retrieve attachment content:
attachmentResult.data
    .pipe(fs.createWriteStream("attachment"))
    .on("finish", () => {
        fs.readFile("attachment", "utf8", (err, data) => {
            if (err) {
                console.error("Error reading file:", err);
                return;
            }
            console.log("Content of attachment:", data);
            next();
        });
    });

Syntax

const getAttachmentOp = new GetAttachmentOperation(documentId, name, type, changeVector);
Parameter Type Description
documentId string Document ID that contains the attachment.
name string Name of attachment to get.
type string Specify whether getting an attachment from a document or from a revision.
("Document" or "Revision").
changeVector string The ChangeVector of the document or the revision to which the attachment belongs.
Mandatory when getting an attachment from a revision.
Used for concurrency checks (use null to skip the check).
Return Value of store.operations.send(getAttachmentOp)
AttachmentResult An instance of class AttachmentResult

class AttachmentResult {
    data;    // Stream containing the attachment content
    details; // The AttachmentDetails object
}

// The AttachmentDetails object:
// =============================
{
    // Change vector of the document that contains the attachment
    changeVector; // string

    // ID of the document that contains the attachment
    documentId?; // string
    
    // Name of attachment
    name; // string;
    
    // Hash of attachment
    hash; // string;
    
    // Content type of attachment
    contentType; // string
    
    // Size of attachment
    size; // number
}