我正在尝试将列表附件从一个站点复制到另一个站点。我只能移动文本文件,但是如果尝试任何其他文件类型,则无法使用。它不会说任何错误,但不会复制。即使文本文档太大,文本文档也不会复制。
这是我到目前为止编写的代码
$(document).ready(function () {
var serverRelativeUrlOfMyFile ="https://sourceurl/Test%20Attachments/Attachments/1/one.pdf";
$.ajax({
url: serverRelativeUrlOfMyFile,
type: "GET",
binaryStringResponseBody: true
}).done(handler);
function handler(mdata){
console.log(mdata);
//i can read the data here in the format it comes
$.ajax({
url: "https://desturl/_api/contextinfo",
type: "POST",
headers: {
"Accept": "application/json;odata=verbose"
},
success: function(contextData) {
$.ajax({
url: "https://desturl/_api/web/lists/getbytitle('Test')/items(1)/AttachmentFiles/add(FileName='one.pdf')",
type: "POST",
contentType: "application/json;odata=verbose",
data: mdata,
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": contextData.d.GetContextWebInformation.FormDigestValue
},
success: function(data) {
alert('success');
},
error: function(jqXHR, textStatus, errorThrown) {
//alert('error');
}
});
}
});
});