【发布时间】:2022-10-04 23:18:54
【问题描述】:
我正在尝试使用 MS Graph API 将 PDF 上传到 SharePoint,并且我能够上传 PDF,但无法读取/预览 PDF。
我尝试将 PDF 文件转换为 Base64 以允许上传,因为它需要是二进制流,但它似乎不起作用。
with open(pdf_filename,"rb") as pdf_file:
pdf_base64 = base64.b64encode(pdf_file.read())
这是我的 PUT 声明:
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)
这是我的标题:
headers = {'Authorization': 'Bearer {}'.format(token), "Content-Type":"application/pdf"}
任何帮助或指导表示赞赏。
谢谢
【问题讨论】:
标签: python pdf sharepoint msgraph