Ich versuche, eine Datei mit dem FileReader-Objekt in eine Dokumentbibliothek hochzuladen, dies aber nicht, da die Dateien mit der falschen Codierung hochgeladen werden.Wie wird die Datei in die Dokumentbibliothek mit CSOM hochgeladen?
Dies ist Code
$("#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();
}
Das Problem im Verkleidung in der Seife befindet sich - String selbst.
Das Umleiten dieser Daten als <Stream>" +window.btoa(data) + "</Stream>
führt dazu, dass die Datei mit ihrem Inhalt als base64-codiert hochgeladen wird. Bilder sind schwarz und Textdateien sind nicht lesbar.
Die Übergabe des Datenobjekts selbst mit <Stream>" + data + "</Stream>\
führt zu einer ungültigen Anforderung.
Wie kann eine Datei mit der FileReader-API in die Dokumentbibliothek in SharePoint 2010 hochgeladen werden?