Blob Action
Blob actions serve binary data from Business Central, such as images, documents, and other files stored in BLOB, Media, or MediaSet fields.
Overview
A Blob action:
- Serves binary data from BC tables
- Supports BLOB, Media, and MediaSet fields
- Configurable MIME type
- Direct streaming to browser
When to Use Blob Actions
Use Blob actions for:
- Product images
- Document downloads
- File attachments
- Media content
- Any binary data storage
Creating a Blob Action
Step-by-Step
- Open the Advanced Portal Designer menu page (search for it in Tell Me) and click Actions
- Click New
- Enter the Web Action code
- Set Type to "Blob"
- Select the Object No. (Table ID)
- Select the Blob Field No.
- Configure MIME type
- Save the action
Configuration Options
Object No.
The table containing the blob data:
- Enter or select the table ID
- Table must have BLOB/Media/MediaSet fields
- Consider access permissions
Blob Field No.
The specific blob field to serve:
- Use lookup to see available fields
- Field types supported: BLOB, Media, MediaSet
- Name displays automatically
MIME Type
APD picks the MIME type automatically:
BLOBfields default toapplication/octet-streamMediaandMediaSetfields use the MIME type stored on the underlyingTenant Mediarecord (set when the media was uploaded)
You can override this by setting Override Mime Type on the action card. Use this when you store JPEGs/PDFs/etc. in a plain BLOB field and need to tell the browser what to do with the content:
| MIME Type | Use Case |
|---|---|
| image/jpeg | JPEG images |
| image/png | PNG images |
| image/gif | GIF images |
| application/pdf | PDF documents |
| application/octet-stream | Generic binary download |
| text/plain | Plain text files |
Cacheable
Enable caching for static content:
- Reduces server load
- Faster repeat loads
- Good for images that don't change
Example: Product Images
Setup
- Create action "PRODUCT-IMAGE"
- Set Type to "Blob"
- Object No.: Item table (27)
- Blob Field No.: Picture field (typically a Media or MediaSet field — MIME type is inferred from the upload)
- Enable Cacheable
How Blob URLs Identify the Record
A Blob action locates the record by reading the table's primary-key field(s) from the URL using TableNo:FieldNo-named parameters (the same naming convention used elsewhere in APD form posts). For the Item table (No. 27), whose primary key is field 1 (No.), the parameter name is 27:1.
Usage in Template
<?open(Item)?>
<?loop(Item,'-')?>
<div class="product">
<img src="?action=PRODUCT-IMAGE&27:1=<?field(Item,"No.")?>" alt="<?field(Item,Description)?>">
<h3><?field(Item,Description)?></h3>
</div>
<?endloop(Item)?>
<?close(Item)?>
Example: Document Download
Setup
- Create action "DOWNLOAD-DOC"
- Set Type to "Blob"
- Object No.: Your document table
- Blob Field No.: Document field
- MIME Type: application/pdf
- Disable Cacheable (documents may change)
Usage
The URL parameter name is <TableNo>:<FieldNo> for each primary-key field of the source table (e.g. for a custom Document table with table number 50100 and ID as primary key field 1, the parameter is 50100:1):
<a href="?action=DOWNLOAD-DOC&50100:1=<?field(Document,ID)?>">
Download Document
</a>
Supported Field Types
BLOB Fields
Traditional blob storage:
- Direct binary content
- No metadata
- Single file per record
Media Fields
Modern media storage:
- Includes metadata
- Thumbnail support
- Better performance
MediaSet Fields
Multiple media items:
- Collection of media
- Index-based access
- Gallery support
URL Parameters
Record Identification
Pass each primary-key field value as a parameter named <TableNo>:<FieldNo>. For the Item table (27, PK field 1):
?action=BLOB-ACTION&27:1=10000
Multiple Key Fields
Compound primary keys use one parameter per key field. For the Sales Header table (36) where field 1 is Document Type and field 3 is No.:
?action=BLOB-ACTION&36:1=Order&36:3=1001
MIME Types Reference
Common MIME Types
| Extension | MIME Type |
|---|---|
| .jpg, .jpeg | image/jpeg |
| .png | image/png |
| .gif | image/gif |
| .svg | image/svg+xml |
| application/pdf | |
| .doc | application/msword |
| .docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| .xls | application/vnd.ms-excel |
| .xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| .zip | application/zip |
| .txt | text/plain |
| .html | text/html |
| .css | text/css |
| .js | application/javascript |
Caching Strategy
When to Cache
Enable caching for:
- Product images
- Company logos
- Static documents
- Rarely changed content
When Not to Cache
Disable caching for:
- User-specific documents
- Frequently updated files
- Sensitive information
Security
Access Control
Blob actions respect:
- Action security profiles
- Authentication requirements
- Table-level security
Record Validation
Consider validating that:
- User can access the record
- Record belongs to user's context
- Blob field has content
Error Handling
Missing Blob
When blob field is empty:
- Returns empty response
- Consider fallback image
- Handle in frontend
Example: Fallback Image
<img src="?action=PRODUCT-IMAGE&27:1=<?field(Item,"No.")?>"
onerror="this.src='images/no-image.png'"
alt="Product Image">
Invalid Record
When record not found:
- Error response returned
- Handle gracefully in UI
- Log for debugging
Performance Tips
Optimize Images
Before storing:
- Resize appropriately
- Compress images
- Use appropriate format
Use CDN
For high-traffic sites:
- Consider CDN caching
- Reduces BC load
- Faster global delivery
Lazy Loading
For lists of images:
<img loading="lazy" src="?action=PRODUCT-IMAGE&27:1=<?field(Item,"No.")?>" alt="">
Gallery Implementation
Multiple Images (MediaSet)
For a MediaSet field, APD currently returns the first media item in the set on each request — there is no index=N URL parameter to pick a specific media item. To present a gallery of all images, store each image in its own record (or in separate fields) so each has its own primary-key value. The pattern below shows one image per Item record:
<div class="gallery">
<img src="?action=PRODUCT-IMAGE&27:1=<?field(Item,"No.")?>" alt="">
</div>
Troubleshooting
No Image Displayed
- Verify action configuration
- Check blob field has data
- Confirm MIME type is correct
- Test URL directly
Wrong Content Type
- Browser may display incorrectly
- Verify MIME type setting
- Check actual file type in BC
Slow Loading
- Enable caching if appropriate
- Optimize image sizes
- Consider CDN for production