问题描述
我正在尝试以节点红色下载tar文件。
downloadTar(sendobj).then(res => {
var bytes = new Uint8Array(byte); // pass your byte response to this constructor
var blob = new Blob([bytes],{type: "application/tar"});
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
var fileName = 'genome.tar';
link.download = fileName;
link.click();
});
function downloadTar(data) {
return new Promise((resolve,reject) => {
$.ajax({
url: nodeRedDownloadTar,type: 'POST',data: data,success: function (result) {
resolve(result);
}
});
});
}
以下是我的红色节点流程,我正在读取a single Buffer Object
中的文件并将其发送到http响应
问题是tar文件未下载。我不确定在哪里出问题。
解决方法
以下流程正常工作,我在http-response节点中使用headers选项将content-type设置为appplication/x-tar
[
{
"id": "6e993a09.f44244","type": "file in","z": "1c834717.22be01","name": "","filename": "/home/pi/test.tar","format": "","chunk": false,"sendError": false,"encoding": "none","x": 600,"y": 580,"wires": [
[
"6e7d5f6f.c9477"
]
]
},{
"id": "df49df3b.d325b","type": "http in","url": "/tar","method": "post","upload": false,"swaggerDoc": "","x": 380,"wires": [
[
"6e993a09.f44244"
]
]
},{
"id": "6e7d5f6f.c9477","type": "http response","statusCode": "","headers": {
"content-type": "application/x-tar"
},"x": 800,"wires": []
}
]