Загрузите файл из http ответа, используя реагировать - PullRequest
0 голосов
/ 28 декабря 2018

У меня есть такой код:

getZipFile(){
  Ext.Ajax.request({
    url: "http://localhost:8081/myAppName/protected/upload/download.do",
    method: 'POST',
    params: {
        entityId: this.props.currentEntityId
    },
    jsonData: litOfDocumentsIdINeed,
    headers: {
      'Content-Type': 'application/json'
    },
    callback: function (records, operation, success) {
      //
      //  I have what I need at this point, it is inside of 'records'
      //  the problem is here: I get the document in records, but I need
      //  to Download it automatically, as soon as I receive these records
      //  But HOW?
      //
    }
  })
}

Итак, я получаю этот файл, это хорошо, но как пойти дальше и автоматически загрузить его?

1 Ответ

0 голосов
/ 28 декабря 2018

Вы можете сделать что-то подобное после получения ответа на обратный вызов -

var filename = 'test' //set the file name here
var blob = new Blob([records], { type: 'add file type here' });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;

document.body.appendChild(link);

link.click();

document.body.removeChild(link);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...