简体   繁体   English

如何使用图 API 将本地文件上传到 sharepoint?

[英]How to Upload a Local File into sharepoint using Graph API?

I am trying to upload a local PDF file into share point via using Graph API but the PUT method is just letting me to create a new file in the SharePoint but not letting me upload a local existing C:/ Drive PDF file I am trying to upload a local PDF file into share point via using Graph API but the PUT method is just letting me to create a new file in the SharePoint but not letting me upload a local existing C:/ Drive PDF file

Here is the API that I am using这是我正在使用的 API

PUT https://graph.microsoft.com/v1.0/drives/ {drive-id}/root:/SharePointFilePath/file-name:/content放置 https://graph.microsoft.com/v1.0/drives/ {drive-id}/root:/SharePointFilePath/file-name:/content

As per here, that is the correct endpoint.根据这里,这是正确的端点。 however, you need to send ithe file as a binary stream in the body.但是,您需要将文件作为二进制 stream 发送到正文中。 https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http

This means that you need to read your local pdf file into a binary stream and send it to the endpoint in the body of the put request.这意味着您需要将本地 pdf 文件读入二进制 stream 并将其发送到 put 请求正文中的端点。 as a test for example, you could create a regular text file with the body as string and contenttype as text.例如,作为测试,您可以创建一个常规文本文件,其中正文为字符串,内容类型为文本。

also if it's larger than 4MB, then you need to use a different method.如果它大于 4MB,那么你需要使用不同的方法。 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession mainly an uploadsession. https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession主要是一个上传会话。

Previous test script to upload file to SharePoint by PnP PowerShell.以前的测试脚本通过 PnP PowerShell 将文件上传到 SharePoint。

https://social.technet.microsoft.com/Forums/msonline/en-US/25191b51-41dd-4f4b-93aa-a46594c9a184/uploading-a-file-to-sharepoint-online-using-microsoft-graph-api?forum=onlineservicessharepoint https://social.technet.microsoft.com/Forums/msonline/en-US/25191b51-41dd-4f4b-93aa-a46594c9a184/uploading-a-file-to-sharepoint-online-using-microsoft-graph-api?论坛=在线服务共享点

Connect-PnPOnline -AppId 'yourAzure app id' -AppSecret "yourAzure app secret" -AADDomain 'xxx.onmicrosoft.com'
$accessToken= Get-PnPAccessToken
$apiUrl = "https://graph.microsoft.com/v1.0/sites/xxx.sharepoint.com,x,x/drives/driveid/items/01AKXHS4ELSEOTLPZHZZDYYBOW57WR6HK6:/test.xlsx:/content"
$path="C:\Lee\Script\testdata.xlsx"
$file=[IO.File]::ReadAllBytes($path)
Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl -Method Put -Body $file -ContentType "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用图谱API获得Facebook页面的本地见解? - How to get local insights of Facebook page using graph API? 上传文件到 Windows Sharepoint 使用 Python 3? - Upload File to Windows Sharepoint using Python 3? 如何使用API​​将文件上传到VBA中的BOX - How to upload file to BOX in VBA using API 如何使用 Python 在 Autentique API 中上传文件? - How to upload a file in Autentique API using Python? 如何使用 python 将 csv 文件上传到 API - How to upload csv file to API using python 如何在 ZA7F5F35426B92742117FC9231B5638 中使用 sharepoint REST API 读取文件 - How to read file using sharepoint REST API in Python 如何使用 REST API 更新 SharePoint 在线文件的元数据? - How to update SharePoint online file's metadata using REST API? 如何使用Microsoft Graph API通过自定义列值查找SharePoint文档 - How to find SharePoint documents by custom column value using Microsoft Graph API 如何使用 REST API 作为托管应用程序从客户端上传和获取 SharePoint 文档库中的项目? - How to upload and GET the Items in the SharePoint Document Library from client side using REST API as a HOSTED APP? 如何使用JMeter的REST API Put方法上传文件 - How to upload a file using REST API Put method using JMeter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM