为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 node-red. 中下载 tar 文件?

如何在 node-red. 中下载 tar 文件?

MMMHUHU 2023-04-27 16:13:13
我正在尝试下载 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 文件。我不确定我在哪里制造问题。
查看完整描述

1 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

以下流程正常工作,我使用 http-response 节点中的标头选项将内容类型设置为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": []

    }

]



查看完整回答
反对 回复 2023-04-27
  • 1 回答
  • 0 关注
  • 96 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信