SHOW:
|
|
- or go back to the newest paste.
1 | functions.download = function (param, successCallback, errorCallback, targetFile, totalSize) { | |
2 | for (i in param) { | |
3 | var url = param[i].path + param[i].fileName + param[i].fileType; | |
4 | var filename = param[i].fileName + param[i].fileType; | |
5 | var authToken = cloud.backend.authToken; | |
6 | ||
7 | var xhr = new XMLHttpRequest(); | |
8 | xhr.onreadystatechange = function () { | |
9 | if (xhr.readyState == 4) { // complete. | |
10 | if (xhr.status >= 200 && xhr.status < 300) { | |
11 | - | var blob = new Blob([this.response], { type: 'image/jpg' }); |
11 | + | var blob = this.response; |
12 | successCallback(blob, filename, functions.performSaveSuccess, functions.performSaveError); | |
13 | } else { | |
14 | // response not successfull | |
15 | var error = /<d:error/; | |
16 | if (error.test(xhr.responseText)) { | |
17 | errorCallback("ResponseText: " + xhr.responseText); | |
18 | } else { | |
19 | errorCallback("Kein ResponeText vorhanden"); | |
20 | } | |
21 | } | |
22 | } | |
23 | }; | |
24 | xhr.open("GET", url, true); | |
25 | xhr.responseType = 'blob'; | |
26 | xhr.setRequestHeader("Authorization", "Basic " + authToken); | |
27 | xhr.send(); | |
28 | } | |
29 | ||
30 | functions.performSave = function (blob, filename, successCallback, errorCallback) { | |
31 | window.requestFileSystem( | |
32 | LocalFileSystem.PERSISTENT, 0, | |
33 | function onFileSystemSuccess(fileSystem) { | |
34 | fileSystem.root.getFile(filename, { create: true }, function (fileEntry) { | |
35 | fileEntry.createWriter(function (fileWriter) { | |
36 | fileWriter.onwriteend = function (e) { | |
37 | successCallback(); | |
38 | }; | |
39 | fileWriter.onerror = function (e) { | |
40 | errorCallback(e); | |
41 | }; | |
42 | fileWriter.write(blob); | |
43 | }, errorCallback); | |
44 | }, errorCallback); | |
45 | }) | |
46 | } |