Tuesday, 3 June 2014

SP.RequestExecutor SharePoint Online


function MoveFiles() {
var getUrl = appWebUrl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('/Source%20Library/Source/Test11.docx')/$value?@target='" + targetSiteUrl + "'";
// use the request executor (cross domain library) to perform the upload
var getExecutor = new SP.RequestExecutor(appWebUrl);
getExecutor.executeAsync({
url: getUrl,
method: 'GET',
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": digest
},
binaryStringResponseBody: true,
success: function (data) {
var putExecutor = new SP.RequestExecutor(appWebUrl);
var putUrl = appWebUrl + "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('/Target Library/Dest')/Files/add(url='Test11.docx',overwrite=true)?@target='" + targetSiteUrl + "'";
putExecutor.executeAsync({
url: putUrl,
method: 'POST',
body: data.body,
binaryStringResponseBody: true,
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": digest,
"Content-Length": data.length
},
success: function () {
alert("Success internal");
},
error: function (err1) {
alert(JSON.stringify(err1));
}
});
},
error: function (err) {
alert(JSON.stringify(err));
}
});
}
http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2012/08/19/real-world-apps-for-sharepoint-2013-kudos-part-1.aspx