Hi.
Thank you very much for your answers! Happy for receiving your help.
I did many tests, as I try to copy file into a subfolder of the target library; more over library and folder names contain special characters. My last test was to copy in the rootfolder of a library without special characters, no mure luck.
Here is the code, if you detect somethingdo not hesitate to tell me:
// var fileContentUrl=sourceUrl+"/_api/web/GetFileByServerRelativeUrl('"+fileRelativeUrl+"')/$value";
var fileContentUrl=sourceUrl+"/_api/web/GetFileByServerRelativePath(DecodedUrl=@f)/$value?@f='"+fileRelativeUrl+"'";
var targetSiteUrl=destUrl;
var newFileName=fileName;//New name of added file
var restUrl=targetSiteUrl+"_api/web/GetFolderByServerRelativeUrl('/sites/.../"+ folderName +"')/Files/Add(url='"+ newFileName +"',overwrite=true)";
$.ajax({
url: targetSiteUrl + "/_api/contextinfo",
type: "POST",
headers: {
"Accept": "application/json;odata=verbose"
},
success: function (data) {
var digest = data.d.GetContextWebInformation.FormDigestValue;
var getFileAction = {
url: fileContentUrl,
method: "GET",
binaryStringResponseBody: true,
success: function (getFileData) {
var copyFileAction = {
url: restUrl,
method: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": digest
},
contentType: "application/json;odata=verbose",
binaryStringRequestBody: true,
body: getFileData.body,
success: copyEnded,
error: copyEnded
};
targetExecutor.executeAsync(copyFileAction);
},
error: copyEnded
};
sourceExecutor.executeAsync(getFileAction);
},
error: copyEnded
});
}
function copyEnded(file,sender,args) {
...
So GetFileByServerRelativeUrl did not run, the line with GetFileByServerRelativePath is ok.
The first request is ok (digest is ok), getFileAction is ok, the copyFileAction fails, the error returned when adding the file is "NOT FOUND"
Thanks in advance.
Sincerely yours,
Damien