Line Breaks – Logic App Compose Action

Posted: July 10, 2022  |  Categories: Azure

This describes a gotcha with line breaks in the Logic App compose action. What is more I will show you how to overcome the issue.

This story starts with an old post I wrote about posting multi-form data. In this I show how to do this using BizTalk Server and propose how do it using a Logic App. Recently the endpoint which we post to began to fail with 500 internal server error. Contacting the third party we found out there was a large framework upgrade on their side. The old framework (Nancy) accepted mal formed requests. The new framework (ASP.NET core) rejects requests if they are malformed.

In short we could not use the BizTalk MIME encoder anymore to create the Content-Disposition header. Thus I resorted to the Logic App solution in my previous post.

 

The Line Break problem

Accordingly the Content-Disposition header is created in a compose shape. Unfortunately we still got a 500 error. This time the error was “Line length limit 100 exceeded”. Google says this is to do with line breaks in multi part form data. Sure enough looking at the codeview of the Logic App I see \n line breaks instead of \r\n.

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose_multipart_form_data": {
                "inputs": "Content-Type: multipart/form-data; \n\nboundary=\"@{variables('GUID')}\" \n--@{variables('GUID')} \n\nContent-Disposition: form-data; name=\"\"; filename=\"invoice_@{triggerBody()?['SessionId']}.xml\" \n\n@{body('IF_INVOICE1_1_2_GS1_ecomm_invoice')} \n\n--@{variables('GUID')}-- ",
                "runAfter": {
                    "Set_GUID": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
           

The Line Break solution

Thus changing the compose action to use CTRL LF line breaks the 500 error disappears.

--@{variables('GUID')}\r\nContent-Disposition: form-data; name=\"\"; filename=\"invoice_@{triggerBody()?['SessionId']}.xml\"\r\n\r\n@{body('IF_INVOICE1_1_2_GS1_ecomm_invoice')}\r\n--@{variables('GUID')}--

Conclusion

To conclude with the take home point is that the default line end in a Logic App compose action is LF not CTTRL LF. It surprised me that Microsoft are using “Linux” like line endings and not “Windows” like ones.

turbo360

Back to Top