从SharePoint外部的另一个应用程序上载在线SharePoint网站集文档库中的文档
-
我已经开发了在Online SharePoint 2016网站集上运行的SharePoint应用.
I have developed a SharePoint App that is running on Online SharePoint 2016 site Collection.
具有另一个在我的其他在线服务器上运行的带有Rest API的软件应用程序.更多此应用程序是完全使用HTML,Javascript/JQuery开发的.没有服务器端脚本.
Have another Software Application with Rest API that is running on my another Online server. More this app is purely developed using HTML,Javascript/JQuery. no server side scripting.
更多SharePoint应用程序已与我的软件应用程序牢固集成(使用Ajax调用进行数据提取).
More SharePoint App strongly integrated with my Software Application (using Ajax calls for data fetching).
现在的问题是,我想从软件应用程序将文件上传到SharePoint.
Now the issue is, i want to upload files into SharePoint from Software Application.
注意:根据我的研发,Office 365联机帐户中不提供匿名访问.
Note: Anonymous access is not available in Office 365 Online account as per my R&D.
请帮助并提前致谢.
您可以按照以下步骤使用REST API和jQuery上传文件:
You can follow the steps below to upload a file by using the REST API and jQuery:
- 使用需要HTML5支持的FileReader API将本地文件转换为数组缓冲区. jQuery(document).ready函数在浏览器中检查FileReader API支持.
- 通过使用文件夹文件集合上的Add方法将文件添加到Shared Documents文件夹中. 数组缓冲区在POST请求的正文中传递.
- 通过使用上载文件的ListItemAllFields属性获取与上载文件相对应的列表项.
- 使用MERGE请求更改列表项的显示名称和标题.
- Convert the local file to an array buffer by using the FileReader API, which requires HTML5 support. The jQuery(document).ready function check FileReader API support in the browser.
- Add the file to the Shared Documents folder by using the Add method on the folder's file collection. The array buffer is passed in the body of the POST request.
- Get the list item that correspond to uploaded file by using the ListItemAllFields property of uploaded file.
- Change the display name and title of the list item by using a MERGE request.
这些示例使用getfolderbyserverrelativeurl端点到达文件集合. 您还可以使用列表端点(例如:…/_api/web/lists/getbytitle('')/rootfolder/files/add).
These examples use the getfolderbyserverrelativeurl endpoint to reach the file collection. You can also use a list endpoint (example: …/_api/web/lists/getbytitle('')/rootfolder/files/add).
For more information, please review the following link: Upload a file by using the REST API and jQuery