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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Sending PDF file conve...
Power Automate
Unanswered

Sending PDF file converted to base64 to an Endpoint via HTTP POST request

(0) ShareShare
ReportReport
Posted on by

Hi Guys.

 

I am using Xamarin Forms and I have a requirement which I must send a PDF file that is converted to base64 string to an API Endpoint.

I'm having trouble sending it. I always receive this error. 

"HTTP 406 Not Acceptable. There was an error with your request. Please check your payload and then try again."

 

This is the Endpoint and the details of the Json body.

Endpoint

 

HTTP-POST:

https://goodmorning-axa-dev.azure-api.net/upload

 

HTTP-HEADERS:

x-axa-api-key: your-key

Content-Type: application/json

 

Request Body JSON

{

"file": {

"mime": "application/pdf",

"data": "base64-data="

}

}

 

Here is how I convert my PDF to base64

 

 private async Task ConvertPdf()
 {
 const string pdfFileName = "MyPDF.pdf";

 using (var pdfStream = await FileSystem.OpenAppPackageFileAsync(pdfFileName))
 {
 using (var pdfReader = new StreamReader(pdfStream))
 {
 var fileContents = await pdfReader.ReadToEndAsync();
 pdfBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(fileContents));
 }
 }
 }

 private async void Submit()
 { 
 var file = new MyFile();
 var pdf = new PdfFile();
 file.MimeType = "application/pdf";
 file.Base64Data = "base64-data=" + pdfBase64;
 pdf.myFile = file;
 await _iregister.Send(pdf.myFile);
 }

 

 

This is my HTTP post request.

The myFile is my PDF that is already converted to base64 string.

 

 var apiKey = "######################";
 var jsonContent = JsonConvert.SerializeObject(myFile);
 string baseUrl = "https://goodmorning-axa-dev.azure-api.net/upload";

 HttpClient httpClient = new HttpClient();
 httpClient.DefaultRequestHeaders
 .Accept
 .Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

 HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, baseUrl);
 requestMessage.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
 requestMessage.Headers.Add("x-axa-api-key", apiKey);

 HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage);
 string responseAsString = await responseMessage.Content.ReadAsStringAsync();

 if (responseAsString != null)
 {
 Console.WriteLine(responseAsString);
 }

 

Here is the format of the serialized JSON file. (I made it shorter just to show the format)

 

{
 "mime":"application/pdf",
 "data":"base64-data=JVBERi0xLjQKJe+/ve+/ve+/ve+/vQoxIDAgb2JqIAo8PAovU3VidHlwZSAvRm9ybQovVHlwZSAvWE9iamVjdAovTWF0cml4IFsxIDAgMCAxIDAgMF0KL0Zvcm1UeXBlIDEKL1Jlc291cmNlcyAKPDwKL1Byb2NTZXRzIFsvUERGIC9UZXh0IC9JbWFnZUIgL0ltYWdlQyAvSW1hZ2VJXQowolJUVPRgo="
}

 

I am not sure if I am missing something in the Header or Body. Please help.

Categories:
I have the same question (0)
  • PrasadAthalye Profile Picture
    on at

    @stifler10 - Can you add accept header?

     

    Accept: application/json

     Like and Mark this as answer if it resolves your issue.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi was this solve? Because I am also having thesame problem and error code.

  • errollocampo Profile Picture
    2 on at

    I know it is quite late for me to answer this but I have the exact problem encountered for my interview exam, just replaced 

     file.Base64Data = "base64-data=" + pdfBase64;

    to file.Base64Data = pdfBase64; 

    got HTTP 200 response:

    {"Message":"HTTP 202 Accepted. Welcome Back! Resume uploaded on our system. Would you be available for a technical interview? Please try and schedule a time in our final endpoint can be found at https://xxxxxxxxxx","Result":202}

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 Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 250 Super User 2026 Season 1

#2
Expiscornovus Profile Picture

Expiscornovus 222 Most Valuable Professional

#3
Haque Profile Picture

Haque 174

Last 30 days Overall leaderboard