linux 如何使用REST API和CURL将文件上传到SharePoint Online

vatpfxk5  于 2023-04-11  发布在  Linux
关注(0)|答案(1)|浏览(210)

我一直在梳理微软关于REST API的文档,以操作SharePoint Online文档树中的文件。我几乎找到了我的解决方案,但遇到了一个问题。
我正在Linux服务器上运行CURL命令。在Linux的/tmp目录中,我有一个文件“a.txt”。我可以使用CURL在SharePoint Online上创建新文件,但无法使用相同的命令上传现有文件。
当我指定“Content-Length:0”,此命令成功地在我们的SharePoint上创建了一个新文件

curl -X POST -i -H "Authorization: Bearer tokenabc" -H "Content-Length: 0" -s "https://tenant.sharepoint.com/teams/testSite/_api/web/GetFolderByServerRelativeUrl('%20Shared%20Documents')/Files/add(url='a.txt',overwrite=true)"

但是,当我尝试从/tmp目录实际上载文件时,(我在/tmp目录中运行CURL命令,我更改“Content-Length:4000”),我没有得到任何响应,也没有创建任何文件。

curl -X POST -i -H "Authorization: Bearer tokenabc" -H "Content-Length: 4000" -s "https://tenant.sharepoint.com/teams/testSite/_api/web/GetFolderByServerRelativeUrl('%20Shared%20Documents')/Files/add(url='a.txt',overwrite=true)"

我似乎不知道如何使用这个API命令从Linux服务器上传我的文件

uurv41yg

uurv41yg1#

您可以尝试使用图形API将upload files连接到SharePoint Online。

PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
Content-Type: text/plain

The contents of the file goes here.

相关问题