Hello, I am trying to upload files to SharePoint using HTTP. I have succeeded to upload text files to a SharePoint folder without issues, but when I upload Excel files, at opening the Excel files, I get an error saying that the excel file is corrupt. I think it is a problem with how to convert the binary content in a way that is understandable by Excel.
FLOW COMPONENTS
1. HTTP POST will give you the URL that you should call to send the file content.
Copy the URL that you will get from this component, as soon as you save your flow. This is the URL that you will have to call to send the file to.
2. Parse JSON with a schema that reads the site_address, application_name, and target_path and file content (see it below)
{
"type": "object",
"properties": {
"site_address": {
"type": "string"
},
"target_path": {
"type": "string"
},
"file_name": {
"type": "string"
},
"file_content": {
"type": "string"
}
}
}3. SharePoint Create File
The Json variables read in the step below to feed site_address (the URL of the target SharePoint site), folder_path (The path to the library/folder in SharePoint where you will save your file), file_name (the name of the file you will upload) and file_content (the content of your file).

The Python code to upload the file to SharePoint is shown below:
import requests
import json
def upload_text_file_to_powerautomate(site_address, file_location, file_name, target_path):
"""
Description: uploads a text file to a SharePoint folder, whose path is specified using a PowerAutomate flow.
Make sure the flow is turned on
:site_address: SharePoint site address
:target_path: Path to the folder in the SharePoint site where the file will be uploaded to
:file_location: Local folder in the sending computer that is sending the file
:file_name: Name of the file that will be uploaded
"""
power_automate_url = "<the_url_from_your_power_automate_https_component" # copy / paste this URL from PowerAutomate HTTPS component
full_file_location = os.path.join(file_location, file_name) # puts together the file location and file name
with open(full_file_location, 'rb') as f:
file_content = f.read() # read the content of the file
data = {
'site_address': site_address,
'target_path': target_path,
'file_name': file_name,
'file_content': file_content
}
data_json = json.dumps(data) # converts the dictionary to a json format
r = requests.post(power_automate_url, json= data_json) # uploads the json data to the PowerAutomate HTTP web service
# calling the function to upload the file to SharePoint
upload_text_file_to_powerautomate(
site_address= "https://<your_target_sharepoit_site>"
file_location= "<where_you_have_the_file_to_upload>, e.g.c:\my_folder_location"
target_path= "your_target_path, e.g. /Shared Documents/test"
file_name= "my_text_file.txt"
) the code above uploads text files and also can upload Excel file, but the problem I get is when I upload an excel file to SharePoint and I try to open the Excel file, I get an error saying that the file is corrupt
I am pretty sure is because somehow I have to decode the binary content in a way that Excel is able to understand it. If someone knows how to convert this content, we have the full solution to upload Excel files to SharePoint using HTTP. Any help is greatly appreciated.
Best regards,
- Noah