[英]“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.