def handle_file_upload(file_to_upload):
# Getting the authenticated user credentials from allauth_office365
social = request.user.social_auth.get(provider='office365') #Im using a different authentication backend/provider than the author did in the article
access_token = social.extra_data['access_token']
# build our header for the api call
headers = {
'Authorization' : 'Bearer {0}'.format(access_token),
}
# build the url for the api call
# Look at https://dev.onedrive.com/items/upload_put.htm for reference
url = 'https://{tenant}.sharepoint.com/api/v2.0/drive/root:/' + file_to_upload.name + ':/content'
# Make the api call
response = requests.put(url, data=open(file_to_upload, 'rb'), headers=headers)
return response