Hi @BrianC,
You will need to implement a function to recursively upload chunks using the Office365-rest-python-client to form the basis for the connection. Please refer to following code
def sharepoint_upload_chunked(blob_path: Path, filename: str, sharepoint_folder: str, chunk_size: int):
'''
input:
blob_path : path to binary file to upload
filename : filename you want to name the upload
sharepoint_folder : the name of the folder you want to upload to
chunk_size : size of the chunks in bytes. Used in recursion.
'''
#log in
ctx = ClientContext(URL).with_credentials(
ClientCredential(CLIENT_ID, CLIENT_SECRET))
with open(blob_path, 'rb') as f:
first_chunk = True
size_previous_chunk = 0
offset = 0
filesize = os.path.getsize(blob_path)
URL = https://myorg.sharepoint.com/sites/myapp
#take url after "sites". You are already logged in to myorg.sharepoint.com via ctx (context)
file_url = URL[29:] + f"/{sharepoint_folder}" + filename
sharepoint_folder_long = url[29:] + f"/{sharepoint_folder}"
#each upload needs a guid. You will reference this guid as you upload.
upload_id = uuid.uuid4()
#consume the data in chunks.
while chunk := f.read(chunk_size):
#see GitHub for progress bar code. This is for large uploads so it really helps.
progressbar(offset, filesize, 30,'■')
#start upload
if first_chunk:
#you need to initialize an empty file to upload into.
print("adding empty file")
endpoint_url = f"{url}/_api/web/getfolderbyserverrelativeurl('{sharepoint_folder_long}')/files/add(url='{filename}', overwrite=true)"
upload_data(ctx, endpoint_url, bytes())
endpoint_url = f"{url}/_api/web/getfilebyserverrelativeurl('{file_url}')/startupload(uploadID=guid'{upload_id}')"
response = upload_data(ctx, endpoint_url, chunk)
first_chunk=False
#Finish upload. if the current chunk is smaller than the previous chunk, it must be the last chunk.
elif len(chunk) < size_previous_chunk:
endpoint_url = f"{url}/_api/web/getfilebyserverrelativeurl('{file_url}')/finishupload(uploadID=guid'{upload_id}',fileOffset={offset})"
progressbar(filesize, filesize, 30,'■')
response = upload_data(ctx, endpoint_url, chunk)
print(response)
#continue upload.
else :
#continue to consume the chunks and upload.
endpoint_url = f"{url}/_api/web/getfilebyserverrelativeurl('{file_url}')/continueupload(uploadID=guid'{upload_id}',fileOffset={offset})"
response = upload_data(ctx, endpoint_url, chunk)
#length in characters, not in bytes)
size_previous_chunk = len(chunk)
offset = offset + size_previous_chunk
You could get the full code in the following document