红色节点在http-request节点中发送文件不起作用

问题描述

我正在尝试通过http-request节点发送文件,但是它不起作用。

请找到以下红色节点流的图像。

enter image description here

请求正文节点中,添加了以下代码。

const inputFile = msg.payload;

const dataJson = 
{
    'name': 'testName','description':'testdescription','inputfile': inputFile
};
msg.payload = dataJson;
msg.url = 'myAPIurl';

msg.headers = {
    'authorization': 'Bearer TOKEN Here','cookie': 'Cookie here','content-type': 'multipart/form-data;'
};

return msg;

这给出了错误的请求错误。

Read File节点中,我尝试同时选择两个选项A single UTF8-Stringa single Buffer Object,但仍然遇到相同的错误


但是我尝试使用request模块在函数节点内部调用API。它给出了适当的响应。

const request = global.get("request");
const fs = global.get("fs");

const url = 'API';

const tkn = 'TOken Here';
const cookie = 'cookie here';

const fl = fs.createReadStream('/tmp/node-red/app/data/filename.txt');
var options = {
    method: 'POST',url: url,headers: {
        'Authorization': tkn,'Cookie': cookie,},formData: {
        "name": "test121","description": "",inputfile: fl
    }
};

request(options,function (err,resp,body) {

    console.log(body);

});

return msg;

如果使用http-request节点,我不确定在哪里出错。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)