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)
base64ToBinary(triggerBody()?['$multipart']?[0]?['body']?['$content'])
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.
Here you don't need to convert to binary:
base64ToBinary(triggerBody()?['$multipart']?[0]?['body']?['$content'])
Design
which worked for me:
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:
Output:
File got created in sharepoint:
There is nothing wrong ion Logic app workflow, you need to just use its content, not convert it.