使用API Postman上传文件到SharePoint

4
我想通过使用Rest API将文件上传到SharePoint,但是我尝试了以下操作却没有成功。

enter image description here

控制台: POST

https://test.sharepoint.com/sites/BusinessDevelopment/Shared%20Documents/Upload_BMT/_api/web/GetFolderByServerRelativeUrl('P_FIRST')/Files/add(url='abdabd.pdf',overwrite=true):

"请求头": {
"content-length": "100000",
"authorization": "Bearer access token",
"user-agent": "PostmanRuntime/7.28.4",
"accept": "*/*",
"postman-token": "11",
"host": "test.sharepoint.com",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive",
"content-type": "multipart/form-data; boundary=--------------------------327461050037851785007682"

"请求主体": { "": "" },
"响应头": {
"cache-control": "private, max-age=0",
"expires": "Mon, 20 Dec 2021 05:18:53 GMT",
"last-modified": "Tue, 04 Jan 2022 05:18:53 GMT",
"vary": "Origin",
"p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"",
"x-sharepointhealthscore": "2",
"x-aspnet-version": "4.0.30319",
"sprequestguid": "375b13a0-70ce-c000-bacc-4fdfeefc7910",
"request-id": "375b13a0-70ce-c000-bacc-4fdfeefc7910",
"ms-cv": "oBNbN85wAMC6zE/f7vx5EA.0",
"strict-transport-security": "max-age=31536000",
"x-frame-options": "SAMEORIGIN",
"content-security-policy": "frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com *.powerapps.com *.yammer.com *.officeapps.live.com *.office.com *.stream.azure-test.net *.microsoftstream.com *.dynamics.com;",
"x-powered-by": "ASP.NET",
"microsoftsharepointteamservices": "16.0.0.21924",
"x-content-type-options": "nosniff",
"x-ms-invokeapp": "1; RequireReadOnly",
"x-cache": "CONFIG_NOCACHE",
"x-msedge-ref": "Ref A: 3C3309D8FC4C43CAA72F28D56F17244B Ref B: ZRHEDGE1219 Ref C: 2022-01-04T05:18:53Z",
"date": "Tue, 04 Jan 2022 05:18:53 GMT",
"content-length": "0"

你是自己放置内容长度头部还是让Postman自动计算? - hanut
是的,我放置了10000。 - BODYBOND
尝试移除内容长度并让其自动设置。 - hanut
是的,我移除了内容长度并使用了此URL http://test.sharepoint.com/sites/testsite/_api/web/GetFolderByServerRelativeUrl('/Library Name/Folder Name')/Files/add(url='a.txt',overwrite=true) .. 但它会出现错误:未授权操作。 - BODYBOND
@BODYBOND 我不知道如何获取“Bearer访问令牌”,你能告诉我吗? - KevinBui
1个回答

3

网址应该像下面这样

网址: http://test.sharepoint.com/sites/testsite/_api/web/GetFolderByServerRelativeUrl('/Library Name/Folder Name')/Files/add(url='a.txt',overwrite=true)


非常感谢,使用此URL后出现错误:system.unauthorizedaccessexception尝试执行未经授权的操作...我确定令牌是正确的! - BODYBOND
如果我使用相同的令牌通过以下URL进行GET请求:https://test.sharepoint.com/_api/web/Lists/,它可以正常工作! - BODYBOND
请检查您客户端 ID 的权限。您的客户端 ID 可能只有读取访问权限。您可以尝试授予该 ID 完全控制访问权限。 - RaytheonXie-MSFT
仍然是相同的错误。 - BODYBOND
这个错误已经修复,谢谢。 - BODYBOND
1
很高兴你找到了解决这个问题的方法。感谢你的分享。 - RaytheonXie-MSFT

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接