cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
markjones
Frequent Visitor

HTTP POST multipart/form-data with binary file gives BadRequest: The character set provided in ContentType is invalid

Scenario

Uploading a document to an API using HTTP.

 

The API requires the following information:

 

POST https://api-specificEndpoint.com/v1/documents/upload HTTP/1.1
Host: myhost.com
api_key=123&workflow_id=456&userfile={file}

 

The API will throw a 307 redirect and come back with:

 

<?xml version="1.0" encoding="UTF-8"?>
<documents_response>
    <status>203</status>
    <message>userfile is not specified</message>
    <url>https://web1-region.specificEndpoint.com/v1/documents/upload/UBqvQjgkIxReOHh2t94w.8BH23wqGQDIhO64XA_qrbmmvX3yrGKiEr0LWrGmYiS5MXFLsYBTv.XV8ax5Xg_NqgP41P2S0Lgv</url>
    <expire>1408672099</expire>
</documents_response>

 

 

A secondary request using the URL provided in the response fails runtime with:

BadRequest. Http request failed: 'The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set.'.

 

In fact the request was successful but the response cannot be processed due to the runtime error.

The body of the request is as follows:

 

{
    "inputs": {
        "method": "POST",
        "uri": "@variables('RegionalURL')",
        "body": {
            "$content-type": "multipart/form-data",
            "$multipart": [
                {
                    "headers": {
                        "Content-Disposition": "form-data; name=\"api_key\""
                    },
                    "body": "@binary(variables('pAPIKey'))"
                },
                {
                    "headers": {
                        "Content-Disposition": "form-data; name=\"workflow_id\""
                    },
                    "body": "@binary(variables('pWorkflowID'))"
                },
                {
                    "headers": {
                        "Content-Disposition": "form-data; name=\"userfile\"; filename=\"Test.pdf\""
                    },
                    "body": {
                        "$content-type": "application/pdf",
                        "$content": "@base64(outputs('Get_file_content_using_path')?['body'])"
                    }
                }
            ]
        }
    }
}

 

 

Postman has no issue with posting to the endpoint.

0 REPLIES 0

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (1,180)