.pipe()html
request(Base.mergeRequestOptions({ http: DWY_GLOBAL.server.Static.http, host: DWY_GLOBAL.server.Static.host, port: DWY_GLOBAL.server.Static.port, headers:{'Content-type':'application/json'}, method: 'post', url: '/zipDownload', body:JSON.stringify(data), }, req, res)).pipe(res) request(Base.mergeRequestOptions({ method: 'get', url: '/api/orders/completeSet/export?'+ queryString.stringify(req.query), }, req, res)).pipe(res)
2.Blobnode
$http.post(URL , { parameter:parameter },{ responseparameterType: 'arraybuffer' }).then(function (res) { var blob = new Blob([res.data], {type: 'application/vnd.ms-excel'}),fileName = '文件名稱'; downFile(blob, fileName); )}; function downFile(blob, fileName) { if (window.navigator.msSaveOrOpenBlob) { navigator.msSaveBlob(blob, fileName); } else { var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = fileName; link.click(); window.URL.revokeObjectURL(link.href); } }
3.模擬a標籤json
const saveLink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a'); saveLink.href = 'http://jhtcc.com/Img/5a6e9b150aa98.png'; saveLink.download = '5a6e9b150aa98.png'; const event = document.createEvent('MouseEvents'); event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); saveLink.dispatchEvent(event);