web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Business Central API Integration with Third-Party Software Using POST for BLOB Field

(9) ShareShare
ReportReport
Posted on by 107
Hi Everyone, 
 

I am currently working on integrating Microsoft Dynamics 365 Business Central with a third-party application. As part of this integration, the third-party software needs to send a file to Business Central via an API (Page, Codeunit, or Query). This file will be stored in a field of type BLOB.

At present, I have exposed a Page API, and they are able to send the file using a PATCH request. However, the third-party system requires a POST request instead of PATCH.

Could anyone advise on the recommended approach to support POST requests for uploading BLOBs to Business Central? Would it be more appropriate to implement this through a custom API Page or a Codeunit, and how should the BLOB handling be structured?

Thank you in advance for your support!

 

Best Regards,

Suketu Piprotar
I have the same question (0)
  • Suggested answer
    Kamal Khakhkhar Profile Picture
    1,274 on at
    Hii there ,
    If the third-party can't support base64, create a proxy in Azure to transform binary to base64 before sending to BC.
    also you can create a API Pages , Codeunit , table as per requirement .
     
    If you found your reference/Answer . please mark it answered.
     
    Thank You.
    Kamal Khakhkhar
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,631 Super User 2025 Season 2 on at
  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    8,760 on at

    Hi Suketu,

    You're absolutely right to explore alternatives to PATCH, especially when the third-party system mandates a POST request for file uploads. BC’s standard API pages typically support PATCH for updating BLOBs, but you can absolutely support POST by designing a custom API Page or Codeunit.

    Let’s break it down:

     

    1. Why PATCH works by default and POST doesn’t
    Standard API Pages in BC are designed for entity updates, which is why PATCH is the default method for modifying BLOB fields. POST is reserved for creating new records, and doesn’t natively support BLOB streaming unless explicitly handled.

     

    2. Recommended approach: Custom API Page + Codeunit
    To support POST for BLOB uploads:

    • Create a custom API Page that exposes the record with the BLOB field
    • Add a Codeunit with a procedure that accepts a Text or InStream parameter
    • Use CreateInStream and CreateOutStream to handle the BLOB field
    • Trigger the Codeunit via an action on the API Page, or expose it as a separate endpoint

    Example structure:

    al
    procedure UploadFileViaPost(var Rec: Record "YourTable"; FileContent: Text)
    var
        OutStream: OutStream;
    begin
        Clear(Rec.YourBlobField);
        Rec.Modify(true);
        Rec.YourBlobField.CreateOutStream(OutStream);
        OutStream.WriteText(FileContent);
        Rec.Modify(true);
    end;
     

    You can also use HttpContent and HttpRequestMessage if you're building the integration from BC outward.

     

    3. Alternative: Use Media or MediaSet fields
    If the file is an image or document, consider using Media or MediaSet fields instead of BLOB. These are optimized for file handling and support POST natively via the standard API.

     

    4. Key considerations

    • Ensure the BLOB field is marked with DataClassification = ToBeClassified
    • Use DelayedInsert = true on the API Page to allow POST before record creation
    • Validate stream closure to avoid errors like “Read called with an open stream”
     

    Helpful references:

    Handling BLOB fields on APIs – Stefano Demiliani
    Posting JSON Data in BLOB via POST – Stack Overflow
    BC API Overview – Microsoft Learn


    If you find this helpful, feel free to mark this as the suggested or verified answer.

    Cheers
    Jeffrey

  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at
    Hi, a simple example, hopefully it will give you some hints.
    Dynamics 365 Business Central: Using OData V4 unbound action (Codeunit API?) to communicate and exchange data seamlessly
     
    Thanks.
    ZHU
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,136 Super User 2025 Season 2 on at
    You can support POST for BLOB upload using a custom API Codeunit with InStream/OutStream. Here's a short AL example:
     
    codeunit 50100 BlobUpload
    {
        [ServiceEnabled]
        procedure UploadFile(FileName: Text; Base64Content: Text)
        var
            RecRef: RecordRef;
            InStr: InStream;
            OutStr: OutStream;
            TempBlob: Codeunit "Temp Blob";
        begin
            TempBlob.CreateOutStream(OutStr);
            OutStr.WriteText(Base64Content);
            TempBlob.CreateInStream(InStr);
            TempBlob.ToRecord(SomeTargetRecord); // Your table with BLOB field
            SomeTargetRecord.CalcFields("Your BLOB Field");
            SomeTargetRecord."Your BLOB Field".CreateInStream(InStr);
            // Save the BLOB content as needed
            SomeTargetRecord.Modify();
        end;
    }
     
     
     
    This allows third-party apps to POST base64 files into BC via a Codeunit.
     
     
  • Gerardo Rentería García Profile Picture
    25,154 Most Valuable Professional on at

    Hi, good day
    I hope this can help you, and give you some hints.

    Dynamics 365 Business Central: handling BLOB fields on APIs – Stefano Demiliani

    Best Regards
    Gerardo

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans