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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Unable to upload file Instream to a Custom API using Multipart/Form-Data

(1) ShareShare
ReportReport
Posted on by 22

Hi,
i am consuming an API, where i need to upload on document(instream).
for uploading, i am running Upload mutation of GraphQL so using multipart/form-data.
But getting few errors:
Error 1: Multipart field missing 'Operation'
Error 2: Misordered multipart fields; files should follow 'map'.

Sample Code :

procedure UploadFile(UploadStream: InStream)
var
TempBlob: Codeunit "Temp Blob";
PayloadOutStream: OutStream;
PayloadInStream: InStream;
CR: Char;
LF: Char;
NewLine: Text;
Content: HttpContent;
ContentHeaders: HttpHeaders;
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
OutputResultJson: Text;
begin
CR := 13;
LF := 10;
NewLine += '' + CR + LF;
Content.GetHeaders(ContentHeaders);
ContentHeaders.Clear();
ContentHeaders.Add('Content-Type', 'multipart/form-data;boundary=boundary');

TempBlob.CreateOutStream(PayloadOutStream);
PayloadOutStream.WriteText('--boundary' + NewLine);
// key1 value1
PayloadOutStream.WriteText('Content-Disposition: form-data; name="operations"' + NewLine);
PayloadOutStream.WriteText(NewLine);
PayloadOutStream.WriteText(' {"query": "mutation($file: Upload!){\n upload(input:{ file: $file}){\n uniqueId\n message\n code\n }\n}"}' + NewLine);
PayloadOutStream.WriteText('--boundary' + NewLine);
// key2 value2
PayloadOutStream.WriteText('Content-Disposition: form-data; name="map"' + NewLine);
PayloadOutStream.WriteText(NewLine);
PayloadOutStream.WriteText('{"0":["variables.file"]}' + NewLine);
PayloadOutStream.WriteText('Content-Type: application/octet-stream' + NewLine);
PayloadOutStream.WriteText(NewLine);
// Copy all bytes from the uploaded file to the stream.
CopyStream(PayloadOutStream, UploadStream);
PayloadOutStream.WriteText(NewLine);
PayloadOutStream.WriteText('--boundary');
// Copy all bytes from the write stream to a read stream.
Tem PayloadOutStream.WriteText('--boundary' + NewLine);
// file1
PayloadOutStream.WriteText('Content-Disposition: form-data; name="0"; fileName="Test.pdf"' + NewLine);
PpBlob.CreateInStream(PayloadInStream);
PayloadInStream.ReadText(OutputResultJson);
// Write all bytes from the request body stream.
Content.WriteFrom(PayloadInStream);
Request.Content := Content;
Request.SetRequestUri('https://SampleAPIUrl.com/');
Request.Method := 'POST';
Client.Send(Request, Response);
if not Response.IsSuccessStatusCode() then
Message(Response.ReasonPhrase + '\Error Code : ' + format(Response.HttpStatusCode)); //RV

Response.Content().ReadAs(OutputResultJson);
Message(OutputResultJson);
end;

I have the same question (0)
  • Ravi Profile Picture
    22 on at

    I found one article from this community :

    community.dynamics.com/.../how-to-send-pdf-file-to-multipart-form-data-web-services-in-dynamics-nav

    But there is some issue with it. Images are not loading and related link is not opening as well.

  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,024 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,145 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 705 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans