Sharepoint请求摘要值跨域

时间:2017-04-06 07:21:00

标签: node.js sharepoint sharepoint-2010 sharepoint-2013

我正在NodeJS和ExpressJs上构建一个web应用程序,我试图通过Sharepoint REST Api将文档上传到Sharepoint Online库。

我能够验证,创建和更新列表项。我使用node-sp-auth进行身份验证,express-request发出http请求。

使用我标题中的FormDigestValue访问Sharepoint REST api i。

部首:

Headers['Content-Type'] = 'application/json;odata=verbose';
Headers['X-RequestDigest'] = FormDigestValue;
Headers['Accept'] = "application/json;odata=verbose";
Headers['X-HTTP-Method'] = "POST";

当我尝试在自定义列表中创建/更新列表项时,正常。但是当我尝试上传文档时,我收到以下错误:

body: '{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":
{"lang":"en-US","value":"There is no app context to execute this request."}}}' } }

我用于上传的网址:

siteurl + "/_api/SP.AppContextSite(@TargetSite)/web/lists/getByTitle(@TargetLibrary)/RootFolder/Files/add(url=@TargetFileName,overwrite='true')?" +
        "@TargetSite='" + siteurl + "'" +
        "&@TargetLibrary='" + libraryName + "'" +
        "&@TargetFileName='" + fileName + "'";

帖子请求:

request.post({
    url: url,
    type: "POST",
    headers: uploadHeaders,
    binaryStringRequestBody: true,
    body: fileData,
})

知道我做错了吗?

1 个答案:

答案 0 :(得分:2)

使用此格式代替帖子:

url: url,
type: 'POST',
data: fileData,
processData: false,
headers: { 
    'Accept':'application/json;odata=verbose',
    'X-RequestDigest': digest,
    'Content-Length': fileData.byteLength 
}

如果您还没有RequestDigest,请调用_api / SP.AppContextSite(@TargetSite)/ contextinfo