node-red 使用令牌通过 http 上传附件 (multipart/form-data)

node-red upload attachment over http with token (multipart/form-data)

我在红色节点中重新创建 curl POST 请求时迷路了。 我的银行 API 文档需要像这样形成请求:

multipart/form-data

curl -S -s --cacert GeoTrust_Primary_CA.pem -X POST -F "type=xml" -F "token=aGEMQB9Idh35fxxxxxxxxxxxxxQwyGlQ" -F "file=@C:\davka.xml" https://www.fio.cz/ib_api/rest/import/> result.xml 2>errorlog.txt type errorlog.txt

我真的需要

curl -X POST -F "type=xml" -F "token=aGEMQB9Idh35fxxxxxxxxxxxxxQwyGlQ" -F "file=@C:\davka.xml" https://www.fio.cz/ib_api/rest/import/

但是我无法将 令牌 传递给表单。

还是得到Required String parameter 'token' is not present

我失败了首选 http 请求 或许多 node-red-contrib-send-form(...) 变体。

我的流量:

[{"id":"f0c84434.8907a8","type":"fileinject","z":"6012893b.689db8","name":"/share/result.xml","x":220,"y":300,"wires":[["690ae5f4.37b66c"]]},{"id":"690ae5f4.37b66c","type":"function","z":"6012893b.689db8","name":"","func":"msg.headers = {\n "content-type" : 'multipart/form-data'\n };\nlet databuffer = msg.payload;\n\nmsg.payload = {\n "KEY": {\n "value": databuffer,\n "options": {\n "filename": "data.xml",\n "type": "xml",\n "token": "aGEMQB9Idh35fxxxxxfakexxxxxxxxQwyGlQ"\n }\n }\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":220,"wires":[["6cca79ea.a45f28"]]},{"id":"6cca79ea.a45f28","type":"http request","z":"6012893b.689db8","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://www.fio.cz/ib_api/rest/import/","tls":"","persist":false,"proxy":"","authType":"","x":760,"y":220,"wires":[["8ec9dd16.83be","3f347cc6.b9a114"]]},{"id":"8ec9dd16.83be","type":"debug","z":"6012893b.689db8","name":"File has been sent","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":220,"wires":[]},{"id":"ba973765.11aa88","type":"inject","z":"6012893b.689db8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":220,"wires":[["e75f0fb7.fa71b"]]},{"id":"e75f0fb7.fa71b","type":"file in","z":"6012893b.689db8","name":"","filename":"/share/result.xml","format":"","chunk":false,"sendError":false,"encoding":"none","x":360,"y":220,"wires":[["690ae5f4.37b66c"]]},{"id":"3f347cc6.b9a114","type":"debug","z":"6012893b.689db8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"statusCode","targetType":"msg","statusVal":"","statusType":"auto","x":970,"y":280,"wires":[]}]

您应该能够使用核心 HTTP Request 节点执行此操作。问题是您传递的有效负载的格式。

如果您更改函数节点以像这样构建有效负载,我相信您应该更进一步:


msg.payload = {
    "file": {
        "value": databuffer,
        "options": {
            "filename": "data.xml",
        }
    },
    "type": "xml",
    "token": "aGEMQB9Idh35fxxxxxfakexxxxxxxxQwyGlQ"
}