0
  1. I created a Logic App to trigger to HTTP requests and where in request I send a pdf file inside multipart/form-data and where file content is binary form as specified by application/octet-stream. Below is the actual Python code I used to send the HTTP request.
        file_name = os.path.basename(file_path)
        with open(file_path, 'rb') as file:
            file_content = file.read()

        files = {
            'file_content': (file_name, file_content, 'application/octet-stream')
        }

        response = requests.post(logic_app_url, files=files)
  1. In Logic app, the HTTP request gets triggered and data is received as expected (that I can see). After trigger, I use Sharepoint connector and "Create File" action to create a file. For getting the content of the PDF file from HTTP request, I use the following expression
base64ToBinary(triggerBody()?['$multipart']?[0]?['body']?['$content'])
  1. The file is created to the Sharepoint, however the data is corrupted in the created PDF file.
  • The PDF opens but it is blank.
  • When I inspect the created PDF file, some characters are not correct when comparing to original PDF file.

Additional Information:

Here is the raw output of body from the HTTP trigger (before the Sharepoint connector)

    "body": {
        "$content-type": "multipart/form-data; boundary=17d2fbd65b268c5f0383c18eaeafbfea",
        "$content": "LS0xN2QyZmJkNjViMjY4YzVmMDM4M2MxOGVhZWFmYmZlYQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmaWxlX2NvbnRlbnQiOyBmaWx.....YzE4ZWFlYWZiZmVhLS0NCg==",
        "$multipart": [
            {
                "headers": {
                    "Content-Disposition": "form-data; name=\"file_content\"; filename=\"original_pdf.pdf\"",
                    "Content-Type": "application/octet-stream"
                },
                "body": {
                    "$content-type": "application/octet-stream",
                    "$content": "JVBERi0xLjQKJazcIKu6CjEgMCBvYmoKPDwgL1BhZ2VzIDIgMCBSIC9UeXBlIC9DYXRhbG9nID4......CnN0YXJ0eHJlZgoxNTkyMgolJUVPRgo="
                }
            }
        ]
    }

The file content is correctly base64 encoded (in above it is only partly given). I get exactly the same content if I create base64 encoded string from the file and save it in my Python function to a file locally and compare to content received by the Azure Logic App.

Any ideas would be helpful.

1 Answer 1

1

Here you don't need to convert to binary:

base64ToBinary(triggerBody()?['$multipart']?[0]?['body']?['$content'])

Design which worked for me:

enter image description here

As you created a function app, which also interconnected with storage account, I would suggest you to first send file to storage account and then get it . And there is no need to convert it to binary.

My pdf content looks same as yours, and i have just used it as it is and it worked:

enter image description here

Output:

enter image description here

File got created in sharepoint:

enter image description here

There is nothing wrong ion Logic app workflow, you need to just use its content, not convert it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your response, it is true that I can do this via Azure Blob Storage exactly how you described it. However, it would be more straightforward if the Logic App would work directly with the multipart content I specified, then I would not need to use Azure Blob Storage at all. I do not see why that could not work other than due to possible issue on base64ToBinary function in LogicApps.
@jhakulin, yes it worked perfectly for me, as you can see the output too.
Thanks, I'll accept the answer as that answers the question how to send the file. I'll create a bug to Azure Logic Apps for multipart and base64ToBinary approach as that should work too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.