How to extract attachments from a custom table in Business Central

Victor Manuel Perez Peña 0 Reputation points
2025-08-28T14:06:50.81+00:00

Hello,

I would like to know the proper way to extract or download the file attachments linked to records in a custom table in Business Central. I understand that standard tables like "Purchase Invoices" or "Sales Orders" support attachments through the “Document Attachment” functionality, but in my case, I need to handle attachments associated with a custom table.

Could you please explain the recommended approach or best practices for accessing and exporting these attachments programmatically (AL code, APIs, or other supported methods)?

Thank you in advance for your support.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 37,216 Reputation points MVP Volunteer Moderator
    2025-08-28T16:33:22.1+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    To extract attachments for a custom table in Business Central, the best practice is to leverage the standard Document Attachment framework instead of building a custom BLOB structure.

    Link your custom table to the Document Attachment table using the table ID and record key so attachments are stored consistently.

    To export or download, read the attachment from the Document Attachment record and stream it out.

    For integrations, expose the attachments through a custom API page or extend the standard APIs, using Media or MediaSet fields for the file content.

    If you already have a custom BLOB field, you can stream the content directly, but this is less maintainable and does not leverage native attachment features.

    This approach ensures compatibility with standard UI, APIs, and future upgrades.

    Best practices

    • Reuse Document Attachment unless you have a very specific reason to maintain a separate BLOB structure.

    Always handle InStream/OutStream to avoid loading large files into memory unnecessarily.

    Add proper permissions to allow users or integrations to access attachment records.

    For large integrations, consider batch APIs or Azure Blob Storage for offloading.

    Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.