簡體   English   中英

使用reactJS從http響應下載文件

[英]Download file from http response, using reactJS

我有這樣的代碼:

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?
      //
    }
  })
}

因此,我收到了該文件,很好,但是如何進一步執行並自動下載呢?

得到回調響應后,您可以執行以下操作-

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM