diff --git a/src/common/api/rest-api.js b/src/common/api/rest-api.js index 33c30ac..bd21de6 100644 --- a/src/common/api/rest-api.js +++ b/src/common/api/rest-api.js @@ -66,7 +66,16 @@ class RestAPI { if (res == null || res.status !== 200) { reject(error); } else { - resolve(JSON.parse(res.text)); + if (res.type ==="application/json"){ + resolve(JSON.parse(res.text)); + } else { + // if received data is not JSON it is a File + //create file name: + let parts = url.split("/"); + console.log("res.text has type: ", typeof res.text); + resolve({data: res.text, type: res.type, id: parts[parts.length-1]}) + } + } }); }); diff --git a/src/common/data-managers/rest-data-manager.js b/src/common/data-managers/rest-data-manager.js index db4c610..622119b 100644 --- a/src/common/data-managers/rest-data-manager.js +++ b/src/common/data-managers/rest-data-manager.js @@ -88,7 +88,13 @@ class RestDataManager { if (id != null) { // load single object RestAPI.get(this.requestURL('load/add',id,param), token).then(response => { - const data = this.filterKeys(response[this.type]); + let data; + if (response.hasOwnProperty(this.type)) { + data = this.filterKeys(response[this.type]); + }else{ + // loaded file + data = response; + } AppDispatcher.dispatch({ type: this.type + 's/loaded',