使用 Sharepoint REST API 和 Javascript 从 Sharepoint 外部上传文件? [英] Upload files with Sharepoint REST API and Javascript from outside of Sharepoint?

查看:85
本文介绍了使用 Sharepoint REST API 和 Javascript 从 Sharepoint 外部上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按需将文件(和元数据)上传到 Sharepoint 服务器,无需人工操作.

I need to upload files (and metadata) on demand without human action to a Sharepoint server.

我可以使用 Sharepoint 外部的 Sharepoint REST API 表单吗?我可以启动 NodeJS 服务器并从外部通过 PnPJS 访问吗?

Could I do with Sharepoint REST API form outside Sharepoint? Could I to launch a NodeJS server and access via PnPJS from outside?

推荐答案

是的,我们可以从 SharePoint 外部(即外部网站)对 SharePoint 进行 REST API POST 调用.假设您的外部网站是 "AAA" 并将数据发送到 SharePoint 网站,即 "BBB" - 因此为了在 SharePoint 中进行身份验证,我们需要生成 client_idclient_secret 来自 SharePoint 站点 - 然后在编写对 SharePoint 的 POST 调用时,我们需要使用 client_idclient_secret 代码.

Yes, we can do REST API POST call to SharePoint from outside of SharePoint i.e. external web site. Lets say your external website is "AAA" and sending data to SharePoint site i.e. "BBB" - so in order to authenticate in SharePoint we need to generate the client_id and client_secret from SharePoint site - then while writing the POST call to SharePoint we need to use the client_id and client_secret code.

以下是如何从 SharePoint 生成client_id"和client_secret"的步骤:

为了实现这种访问 - 我们需要从 "client_id 和 client_secret="nofollow noreferrer">https://BBB.sharepoint.com" 站点并在发送数据 "BBB" 站点时在 "AAA" 站点中使用该代码.

In order to achieve this access - we need to generate a client_id and client_secret from "https://BBB.sharepoint.com" site and uses that code in "AAA" site while sending the data "BBB" site.

如何生成client_idclient_secret 代码有很长的步骤.

There is a long steps how to the generate the client_id and client_secret code.

第 1 步:注册加载项

转到您 BBB 网站的此页面 https://.SharePoint.com/_layouts/15/appregnew.aspx

Go to the this page of your BBB site https://.SharePoint.com/_layouts/15/appregnew.aspx

您将在此处获得:客户 ID客户机密

将此信息保存在记事本中.

Save this information in notepad.

第 2 步:授予加载项权限

转到您 BBB 网站的此页面:

Go to this page of your BBB site:

https://.sharepoint.com/_layouts/15/appinv.aspx

https://.sharepoint.com/_layouts/15/appinv.aspx

在 App ID 字段中输入Client ID",然后点击 Lookup 按钮

Enter the "Client ID" in the App ID field and click on Lookup button

现在以 XML 格式输入以下权限请求:

Now enter the below permission request in XML format:

<AppPermissionRequests AllowAppOnlyPolicy="true">
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read" />
</AppPermissionRequests>

第 3 步:检索租户 ID

在 POST man 工具中对该 URL(BBB 站点)执行 GET 请求:

In POST man tool do a GET request for this URL(BBB site):

https:///sharepoint.com/_vti_bin/client.svc/

https:///sharepoint.com/_vti_bin/client.svc/

从 Header 部分,您将获得 realm 值,它只是您的客户端 ID.

From the Header section you will get the realm value which is nothing but your client ID.

最后,当您将客户端 ID客户端机密发送到 AAA 站点(您从中上传文档),它应该是以下格式:

So finally while you are sending the client id and client secret to the AAA site(your source site from where you are uploading the document), it should be in the below format:

client_id   ClientID@TenantID
client_secret   ClientSecret

示例:

client_id: 4b4276d0-74cd-4476-b66f-e7e326e2cb93@10267809-adcb-42b6-b103-c7c8190b3fed
client_secret: nuC+ygmhpadH93TqJdte++C37SUchZVK4a5xT9XtVBU=

现在,当这里的另一个系统是应用程序 AAA 站点" 执行对SharePoint 站点"的 POST 调用时,它是 https://BBB.sharepoint.com",他们需要使用这两个client_idclient_secret键.

Now when the other system here it is application "AAA site" performing the POST call to the "SharePoint site here it is https://BBB.sharepoint.com", they need to use these two client_id and client_secret key.

详细解释在这里:

https://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/

建议:

从这里下载 POST man 工具 https://www.getpostman.com/downloads/

Download the POST man tool from here https://www.getpostman.com/downloads/

使用此工具和上述 client_idclient_secret 代码对 SharePoint 执行示例 POST 请求 - 然后生成适合您的几乎所有编程语言的 POST 请求 API 代码可以使用 POST man 工具使用 - 如果您使用 C# - 您可以获得 C# 等效代码用于 POST 调用 - 然后您可以在 Visual Studio 或您正在使用的任何工具中的实际应用程序中使用相同的代码段.

Do the sample POST request to SharePoint using this tool and the above client_id and client_secret code - then generate POST request API code whichever language suits for you almost all programming languages are available using the POST man tool - if you are working in C# - you can get the C# equivalent code for the POST call - then you can use the same piece of code in your actual application in Visual Studio or whichever tool you are using.

这篇关于使用 Sharepoint REST API 和 Javascript 从 Sharepoint 外部上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆