【发布时间】:2021-12-04 02:29:40
【问题描述】:
在某些情况下,我正在使用sp-rest-proxy 制作一个工具,该工具将使用反应接口从 SharePoint (MS 365) 获取、修改和替换 json 数据。在找出身份验证问题后,我现在遇到了阻止我更新文件的问题。
注意: sp-rest-proxy 带有一个非常方便的界面,可以让您在 localhost 上测试各种路由,下面的块是 SharePoint REST 相关端点。另外,虽然我出于隐私目的使用示例路径,但真实路径中没有特殊字符,这不是“%”问题。
这个端点很好用,可以毫不费力地给我数据
/sites/front/_api/web/GetFileByServerRelativeUrl('sites/homePage/DivisionSite/DeptSite/myLibrary/folder/subFolder/data.json')/$value
但这些会导致 404s
/sites/front/_api/web/GetFolderByServerRelativeUrl('sites/homePage/DivisionSite/DeptSite/myLibrary/folder/subFolder')/files/add(url='data.json',overwrite=true)
/sites/front/_api/web/GetFolderByServerRelativeUrl('sites/homePage/DivisionSite/DeptSite/myLibrary/folder/subFolder')/Files('data.json')
/*
{
"readyState": 4,
"responseText": "{\"error\":{\"code\":\"-2147024893, System.IO.DirectoryNotFoundException\",\"message\":{\"lang\":\"en-US\",\"value\":\"File Not Found.\"}}}",
"responseJSON": {
"error": {
"code": "-2147024893, System.IO.DirectoryNotFoundException",
"message": {
"lang": "en-US",
"value": "File Not Found."
}
}
},
"status": 404,
"statusText": "Not Found"
}
*/
我可以使用界面查看我的文件夹是否存在并包含项目(我的 json 文件)
/sites/front/_api/web/GetFolderByServerRelativeUrl('sites/homePage/DivisionSite/DeptSite/myLibrary/folder/subFolder')
/*
"..." represents stuff I hid for privacy
{
"d": {
"__metadata": {
"id": "...",
"uri": "...",
"type": "SP.Folder"
},
"Files": {
"__deferred": {
"uri": "..."
}
},
"ListItemAllFields": {
"__deferred": {
"uri": "..."
}
},
"ParentFolder": {
"__deferred": {
"uri": "..."
}
},
"Properties": {
"__deferred": {
"uri": "..."
}
},
"StorageMetrics": {
"__deferred": {
"uri": "..."
}
},
"Folders": {
"__deferred": {
"uri": "..."
}
},
"Exists": true,
"IsWOPIEnabled": false,
"ItemCount": 5,
"Name": "otherFolder",
"ProgID": null,
"ServerRelativeUrl": "sites/homePage/DivisionSite/DeptSite/myLibrary/folder/subFolder",
"TimeCreated": "2021-09-20T18:51:29Z",
"TimeLastModified": "2021-10-01T20:03:03Z",
"UniqueId": "...,
"WelcomePage": ""
}
}
*/
但是,当我尝试查看文件时...
/sites/front/_api/web/GetFolderByServerRelativeUrl('sites/homePage/DivisionSite/DeptSite/myLibrary/folder/subFolder')/Files
/*
{
"d": {
"results": []
}
}
*/
(“?$expand=File” 的结果类似)
鉴于我似乎需要 GetFolderByServerRelativeUrl 来替换文件,我真的需要弄清楚那里发生了什么。
附录: 基于一些类似的问题,我也会提到这一点。我的应用权限设置如下:(建议here)
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
</AppPermissionRequests>
【问题讨论】:
标签: sharepoint sharepoint-rest-api