How to Check if an Attachment Exists


  • To check whether a document contains a certain attachment,
    use the method exists() from the advanced.attachments session operations.

  • Calling 'exists' does not load the document or the attachment to the session,
    and the session will not track them.

  • In this page:


Check if attachment exists

const exists = await session
    .advanced
    .attachments
    .exists("categories/1-A", "image.jpg");

if (exists) {
    // attachment 'image.jpg' exists on document 'categories/1-A'
}

Syntax

session.advanced.attachments.exists(docId, attachmentName);
Parameter Type Description
docId string The ID of the document you want to check
attachmentName string The name of the attachment you are looking for
Return Value Description
Promise<boolean> true - The specified attachment exists on the document
false - The attachment does not exist on the document