Users attach PDFs to customers and orders every day. Extensions that store files have three choices: the standard Document Attachment table, a Media or MediaSet field, or a Blob. Which to use, how to add the standard attachment FactBox to your own table, copying attachments to posted documents, and keeping the database from filling with scans.
Business Central stores files in three ways, and the right one depends on who looks at them and how often. Getting it wrong means either a database that grows by gigabytes a month or an integration that cannot find the file it needs.
| Document Attachment | Media / MediaSet field | Blob field | |
|---|---|---|---|
| What it is | The standard table (1173) linking any record to any number of files, with the FactBox users already know | A field type for images and files, stored in platform media storage, deduplicated, streamed to the client | A binary column on your table |
| Use for | User-managed documents on master data and documents: contracts, certificates, scans | Pictures (item images, logos) and files your code displays or returns through an API | Small generated content read only by code (a cached payload, a signature) |
| Visible in client | Attachments FactBox, drill-down, download | Image controls; download via code | Not directly |
| Counts toward storage | Yes (database) | Yes (media storage, reported separately) | Yes (database) |
The standard FactBox works on any table once you tell it how to link. Add the "Document Attachment Factbox" part to your card and list with SubPageLink on your table ID and primary key; subscribe to OnAfterInitFieldsFromRecRef in Codeunit "Document Attachment Mgmt" (or the newer OnBeforeInsertAttachment events) to map your record's key fields into the attachment's "No." / "Line No.". Users then attach, view and delete through the standard UI, and the files are in the standard place for backups, retention and GDPR requests.
The base application copies attachments from a sales order to the posted shipment and invoice by subscribing to the posting events and calling DocumentAttachmentMgmt.CopyAttachments. If your extension posts its own document, do the same from your posting routine.
field(50120; "CON Label"; Media) { Caption = 'Label'; }
// store
Shipment."CON Label".ImportStream(InStr, FileName);
// read back
Shipment."CON Label".ExportStream(OutStr);
// has one?
if Shipment."CON Label".HasValue() then ...
MediaSet holds several; Picture on Item is a MediaSet. Media is deduplicated by content, so ten records with the same logo store it once.
Record Link table, or a URL field) in Business Central. The storage allowance is finite and overage is charged.