简体   繁体   English

从SharePoint 2013 REST API对文件使用moveto或copyto时出现“格式不正确的JSON流”

[英]“Not well formed JSON stream” when using moveto or copyto on file from SharePoint 2013 REST API

I am trying to enable file move and copy operations on files in a sharepoint 2013 document library. 我正在尝试对sharepoint 2013文档库中的文件启用文件移动和复制操作。 I have the list and delete operations working but when I try to call /moveto(newfile=...,flags=1) or /copyto(strnewfile,boverwrite=true) I get an error "Not well formed JSON stream". 我的列表和删除操作有效,但是当我尝试调用/moveto(newfile=...,flags=1)或/ copyto(strnewfile,boverwrite = true)时,出现错误“格式不正确的JSON流”。

I have tried the newurl (or strnewurl) both with and without the site prefix (eg /sites/dev). 我已经尝试了带有或不带有站点前缀(例如/ sites / dev)的newurl(或strnewurl)。 I have separately verified that getfilebyserverrelativeurl is in fact returning the file. 我已经单独验证了getfilebyserverrelativeurl实际上正在返回文件。

Has anyone run into this before? 有人遇到过吗?

function copyFile() {
    var executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync({
        url: appweburl + "/_api/SP.AppContextSite(@target)/web" +
            "/getfilebyserverrelativeurl('/sites/dev/Sample1/Customer.dim')" +
            "/copyto(strnewurl='/Sample1/filename.docx',boverwrite=false)" +
            "?@target='" + hostweburl + "'",
        method: "POST",
        headers: {
            "accept": "application/json;odata=verbose",
            "IF-MATCH": "*"
        },
        success: function (data) {
            alert(JSON.stringify(data));
        },
        error: errorHandler
    });
}

function moveFile() {
    var executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync({
        url: appweburl + "/_api/SP.AppContextSite(@target)/web" +
            "/getfilebyserverrelativeurl('/sites/dev/Sample1/Customer.dim')" +
            "/moveto(newurl='/Sample1/filename.docx',flags=1)" +
            "?@target='" + hostweburl + "'",
        method: "POST",
        headers: {
            "accept": "application/json;odata=verbose",
            "IF-MATCH": "*",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            alert(JSON.stringify(data));
        },
        error: errorHandler
    });
}

I just ran into the same problem. 我只是遇到了同样的问题。 My solution was to use ajax instead of the executor: 我的解决方案是使用ajax代替执行程序:

 $.ajax({ url: SPAppWebUrl + "/_api/SP.AppContextSite(@target)/web/getfilebyserverrelativeurl('" + file + "')/copyto(strnewurl='" + target + "',boverwrite=false)?@target='" + hostweburl + "'", type: "POST", dataType: 'json', headers: { "Accept": "application/json; odata=verbose", "content-type": "application/json; odata=verbose", "IF-MATCH": "*", "X-RequestDigest": $('#__REQUESTDIGEST').val() }, success: successHandler, error: errorHandler }); 

Strange enough when I use the same with the RequestExecutor it doesn't work. 当我与RequestExecutor一起使用时,这很奇怪,它不起作用。

I've found that the copyto URL parameter needs to be server relative, not site relative. 我发现copyto URL参数需要相对于服务器,而不是相对于站点。 So strnewurl='/sites/dev/Sample1/filename.docx' instead of strnewurl='/Sample1/filename.docx' 因此strnewurl='/sites/dev/Sample1/filename.docx'代替strnewurl='/Sample1/filename.docx'

I know all the docs say it's site relative, but this is what's worked for me. 我知道所有文档都说它是相对于站点的,但这对我有用。 I also only include the accept header. 我也只包含accept标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sharepoint Check In Rest API 错误“JSON 流格式不正确” - Sharepoint Check In Rest API Error 'Not well formatted JSON stream' 格式良好的 JSON 文件 - Well Formed JSON file 使用REST API将文件签入到Sharepoint 2013不起作用 - Check In of file using REST API to Sharepoint 2013 not working 使用 XMLHttpRequest 加载 JSON 文件时,Firefox 中出现“格式不正确”错误 - "not well-formed" error in Firefox when loading JSON file with XMLHttpRequest 如何在站点和子站点之间使用Sharepoint 2013中的Rest API和javascript复制文件 - How to copy file using Rest API and javascript in Sharepoint 2013 between site and subsite SharePoint 2013 Library检索所有文件名。 REST API - SharePoint 2013 Library retrieving all file names. REST API 使用REST上传文件时,可以在线SharePoint 2013在线设置其他列值吗? - SharePoint 2013 online can I set other column values when uploading a file using REST? 发送到CouchDB时,Json不是很好 - Not well formed Json when sending to CouchDB 公开Sharepoint 2013 REST API使用JavaScript获取 - Exposing Sharepoint 2013 REST API Get using JavaScript 通过JavaScript在Office 365上使用REST远程访问Sharepoint 2013 - Remotely accessing Sharepoint 2013 using REST on Office 365 from JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM