FileReader 개체를 사용하여 문서 라이브러리에 파일을 업로드하려하지만 파일을 잘못된 인코딩으로 업로드 했으므로 실패합니다. 문자열 자체 - CSOM을 사용하여 문서 라이브러리에 파일을 올바르게 업로드하는 방법은 무엇입니까?
이
코드$("#file").kendoUpload({
async: {
saveUrl: "save",
autoUpload: true
},
upload: function (e) {
$.each(e.files, function() {
var file = this.rawFile;
var reader = new FileReader();
reader.onload = function (e) {
var data = reader.result;
var soapEnv =
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='ht
<soap:Body>\
<CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
<SourceUrl>" + file.name + "</SourceUrl>\
<DestinationUrls>\
<string>"+GetHostname() + folder + "/" + file.name + "</string>\
</DestinationUrls>\
<Fields>\
<FieldInformation Type='Text' DisplayName='Title' InternalName='Title' Value='"+ file.name + "' />\
</Fields>\
<Stream>" +window.btoa(data) + "</Stream>\
</CopyIntoItems>\
</soap:Body>\
</soap:Envelope>";
$.ajax({
url: "/documents/_vti_bin/copy.asmx",
beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"); },
type: "POST",
dataType: "xml",
data: soapEnv,
contentType: "text/xml; charset=\"utf-8\""
}).then(function (data, status) {
var itemUrl = xmlToJSON(data).Envelope.Body.CopyIntoItemsResponse.Results.CopyResult._DestinationUrl;
return documentsUtilities.checkIn(itemUrl);
})
.then(function(res){
//notifiy user and automatically reload the grid
});
};
});
e.preventDefault();
}
메신저 외장는 비누에있는 문제입니다.
해당 데이터를 <Stream>" +window.btoa(data) + "</Stream>
으로 전달하면 파일의 내용이 base64로 인코딩되어 업로드됩니다. 이미지는 검은 색이고 텍스트 파일은 읽을 수 없습니다.
데이터 개체 자체를 <Stream>" + data + "</Stream>\
으로 전달하면 잘못된 요청이 발생합니다.
FileReader API를 사용하여 SharePoint 2010의 문서 라이브러리에 파일을 업로드하는 올바른 방법은 무엇입니까?