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();
}
IMフェーシングは石鹸に配置されている問題である - 文字列そのもの。
そのデータを<Stream>" +window.btoa(data) + "</Stream>
として渡すと、そのコンテンツはbase64でエンコードされた状態でアップロードされます。画像は黒色でテキストファイルは読めません。
データオブジェクト自体を<Stream>" + data + "</Stream>\
に渡すと、不正な要求が発生します。
FileReader APIを使用してSharePoint 2010上のドキュメントライブラリにファイルをアップロードする正しい方法は何ですか?