javascript - 如何下载 node-red 中的 tar 文件?
问题描述
我正在尝试以 node-red 下载 tar 文件。
以下是我下载文件的 JavaScript 代码。
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);
}
});
});
}
以下是我的 Node-Red 流程,我正在读取文件a single Buffer Object
并将其发送到 http 响应
问题是 tar 文件没有被下载。我不确定我在哪里制造问题。
解决方案
以下流程工作正常,我使用 http-response 节点中的 headers 选项将内容类型设置为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",
"z": "1c834717.22be01",
"name": "",
"url": "/tar",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 380,
"y": 580,
"wires": [
[
"6e993a09.f44244"
]
]
},
{
"id": "6e7d5f6f.c9477",
"type": "http response",
"z": "1c834717.22be01",
"name": "",
"statusCode": "",
"headers": {
"content-type": "application/x-tar"
},
"x": 800,
"y": 580,
"wires": []
}
]
推荐阅读
- excel - Excel 中的最大列引用 (xlsx)
- python - 为什么我的 ifft 导致复数的实部是无限的?
- .net - 在 ASP.net 核心 web api 中添加自定义标题 (Swashbuckle.AspNetCore -- Version="5.0.0-rc4")
- java - Mockito 测试抛出“URI 不是绝对的”错误
- java - 将字符串评估为 JAVA / 插值中的 json 访问
- java - AndroidX 生命周期错误,我该如何解决?
- python - 在 Python 中查找行索引和列标签
- c++ - 在模板类成员上使用 std::bind
- android - 当两个班级都在一个活动中时,如何将位图从一个班级移动到另一个班级?
- bash - 通过 bash 更新 yaml