I am trying to upload a PDF to SharePoint using the MS Graph API and I am able to upload a PDF, but the PDF can't be read/previewed.
I've tried converting the PDF file to Base64 to allow it to be uploaded since it needs to be a binary stream but it doesn't seem to work.
with open(pdf_filename,"rb") as pdf_file:
pdf_base64 = base64.b64encode(pdf_file.read())
Here is my PUT statement:
response_upload = requests.put(f"https://graph.microsoft.com/v1.0/sites/{site_id}/drive/root:/Document Folder/PDF_Name.pdf:/content", data=pdf_base64, headers=headers)
Here are my headers:
headers = {'Authorization': 'Bearer {}'.format(token), "Content-Type":"application/pdf"}
Any help or guidance is appreciated.
Thanks