PDF File upload in Logic Apps using multipart/form-data

Tang, Suzanne 26 Reputation points
2021-08-03T13:00:39.06+00:00

I am trying to use Logic Apps to submit a form to external API, including uploading a PDF file.

Two methods were used and none of them worked. Here is the detail.

Method #1: Use "Call service endpoints over HTTP or HTTPS from Azure Logic Apps"
https://learn.microsoft.com/bs-latn-ba/azure/connectors/connectors-native-http#content-with-multipartform-data-type
Result: pdf file was accepted by API but not readable
Code:
"body": {
"$content-type": "multipart/form-data",
"$multipart": [
{
"body": {
"content": "@{body('Get_blob_content')}",
"Content-Type": "application/pdf"
},
"headers": {
"Content-Disposition": "form-data; name=PdfFile; filename=\"@{variables('pdfFileName')}\"",
"Content-Type": "application/pdf"
}
},
{
"body": "param1Value",
"headers": {
"Content-Disposition": "form-data; name=param1Name"
}
},
...
}

Method #2: Manually build body with boundary separators
Result: pdf file was accepted by API but all pages are blank
Code:
"headers": { "Content-Type": "multipart/form-data; boundary=--[my boundary string]", ...},
"body": "--[my boundary string]\r\nContent-Disposition: form-data; name=PdfFile; filename=\"@{variables('pdfFileName')}\"\r\nContent-Type: application/pdf\r\n\r\n \r@{body('Get_blob_content')}\n\r\n--[my boundary string]\r\nContent-Disposition: form-data; name=\"param1Name\"\r\n\r\n\r\n--[my boundary string]--",

I compared the file content from the original file and Logic App activity raw inputs, there is difference and I don't know how it affects the result.

**Original file: **
... stream\nxœì} @TG×öÜ»…²”¥7‘…¥×¥ ¨À ‚ ‚T lô¢K P¬ ±c,±wQ Kl X°kÔØb Æ c4šh [b‰...

Logic App activity raw inputs:
... stream\nx��}\u0007@TG��ܻ����7���ץ\t��\u0002� �T\u0005l�K\u0011P�\u0011�c,�wQ\u0013Kl\u000bX�k��b��\u0014c4�h\u0014[b�....

Also tried base64 encoding with base64 file content, it didn't work either.

Any idea will be greatly appreciated.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,922 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,761 Reputation points
    2021-08-04T06:59:18.207+00:00

    @Tang, Suzanne I have tested the worflow at my end (get the content from storage and upload to your URL) and I couldn't observe the same issue as you have observed. Can you test the below and confirm if you are facing the issue. You can compare the same with your workflow. I am reading the blob (pdf file) from azure storage and passing the file content to my HTTP action.
    I have used requestbin.com to verify the HTTP request and what file content was uploaded.

    Logic App HTTP Action :

    120411-image.png

    At request bin end I have verify the HTTP header passed and the URL where the file is created. Downloaded the pdf file and confirm that the file is same as I have uploaded.

    120269-image.png

    I will suggest you to test the above. For your HTTP URL where you are uploading the file using the suggestion would be use fiddler/postman and confirm if it was successful and if yes then verify the request body and headers.


0 additional answers

Sort by: Most helpful