我自己解决了。有兴趣的可以参考一下解决方案:只需将 responsetype 设置为 arraybuffer 即可。
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) { // complete.
if (xhr.status >= 200 && xhr.status < 300) {
var data = this.response;
successCallback(data, fileName);
} else {
// response not successfull
var error = /<d:error/;
if (error.test(xhr.responseText)) {
console.log("ResponseText: " + xhr.responseText);
} else {
console.log("Kein ResponseText vorhanden");
}
}
}
};
xhr.open("GET", url, true);
xhr.responseType = 'arraybuffer';
xhr.setRequestHeader("Authorization", "Basic " + authToken);
xhr.send();
然后你可以将它保存在你的 successCallback 中,如下所示:
performSave = function (data, filename) {
console.log("perform Save");
console.log(data);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(filename, { create: true }, function (fileEntry) {
fileEntry.remove(
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function (e) {
cloud.functions.performSaveSuccess();
};
fileWriter.onerror = function (e) {
cloud.functions.performSaveError(e);
};
fileWriter.write(data);
}, errorCallback));
}, errorCallback);
})
}
希望这对任何人都有帮助