Has anybody been able to REST Upload cross site/domain of a file to a document Library with REST on SPO 2013 thru embedded page code or NAPA? Wondering how app security is set on the TargetSite? I can do it to a doc lib on the same site, but cross gives me 403 - Denied. User has full control to both sites.
Here's my code. Note the two URLs /sites/dev vs /sites/test
function PerformUpload(fileName, fileData) {
var url;
//var path = appWebUrl; var p = path.split('/');var approot = p[0]+"//"+p[2]+"/"+p[3]+"/"+p[4];
url = 'https://mytenant.sharepoint.com/sites/dev' +
"/_api/SP.AppContextSite(@Target)/web/lists/getByTitle(@TargetLibrary)/RootFolder/Files/add(url=@TargetFileName,overwrite='false')?"+
"@TargetSite='" + 'https://mytenant.sharepoint.com/sites/test'+ "'" +
"&@TargetLibrary='Documents'" +
"&@TargetFileName='CV" + fileName + "'";
alert(url);
$.ajax({
url: url,
type: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
data: JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'Title': 'New title' }),
contentType: "application/json;odata=verbose",
binaryStringRequestBody: true,
body: fileData,
success:successHandler,
error: errorHandler
});
}