Skip to content

Commit

Permalink
SharePoint testing
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdez99 committed Oct 7, 2024
1 parent 3c96c64 commit 9e7c9ab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/scripts/upload_to_sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import glob
from requests_ntlm import HttpNtlmAuth
import urllib.parse

# Get environment vars
url = os.getenv('host_name')
Expand All @@ -10,7 +11,8 @@
client_id = os.getenv('client_id')
client_secret = os.getenv('client_secret')

upload_url = f"https://{url}/{site_name}/{upload_path}"
# Prepare the base part of the upload_url
upload_url_base = f"https://{url}/sites/{site_name}/_api/web/getfolderbyserverrelativeurl('{urllib.parse.quote(upload_path)}')/files/add(url="

# use a wildcard to upload all files in the directory
file_path = os.getenv('file_path')
Expand All @@ -19,6 +21,10 @@
with open(file, 'rb') as content_file: # Open in binary mode
file_content = content_file.read().decode(errors='ignore') # Decode the content

# Prepare the upload_url for this file
filename = os.path.basename(file)
upload_url = upload_url_base + f"'{urllib.parse.quote(filename)}',overwrite=true)"

r = requests.put(
url=upload_url,
data=file_content,
Expand Down

0 comments on commit 9e7c9ab

Please sign in to comment.