У меня есть веб-сервис, который возвращает объект JSON, который включает в себя байтовый массив документа, который должен быть загружен. Как загрузить этот документ с помощью JavaScript?
код Java
File file = new File(path);
bytesArray = new byte[(int) file.length()];
//read file into bytes[]
fileInputStream = new FileInputStream(file);
fileInputStream.read(bytesArray);
JSONObject response = new JSONObject();
response.put("document", bytesArray);
return response;
код JavaScript
var blob = response.document;
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = "tst.pdf";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
Ответ, который я получаю от javascript: response = {"document",Object}
.