在Node-RED中,它具有“文档上层节点”,听起来可以将文件上传到Discovery Service,但是问题是我的客户端想要上传.doc文件。 我当然尝试过,但是发现服务端将有效负载视为json,无法获得预期的结果...
请让我知道是否有人可以帮助我...
真诚的感谢您:)
[
{
"id": "e4faba0c.56b178",
"type": "watson-discovery-v1-document-loader",
"z": "638c0f19.4d555",
"name": "",
"environment_id": "170e0fd8-d7f2-4486-8bd6-6c987162961c",
"collection_id": "8c517d38-164d-415c-9137-5ff5ac08a391",
"filename": "myword.doc",
"default-endpoint": false,
"service-endpoint": "https://gateway-fra.watsonplatform.net/discovery/api",
"x": 580,
"y": 500,
"wires": [
[
"6e29e3ac.0bd18c"
]
]
},
{
"id": "f36b9a78.0eb958",
"type": "http in",
"z": "638c0f19.4d555",
"name": "[POST] interface",
"url": "/interface",
"method": "post",
"upload": true,
"swaggerDoc": "",
"x": 100,
"y": 440,
"wires": [
[
"31ec90da.b573d8",
"5220938b.ddb934"
]
]
},
{
"id": "31ec90da.b573d8",
"type": "function",
"z": "638c0f19.4d555",
"name": "reqProcessor",
"func": "msg.payload = msg.req.files[0].buffer;\n\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 290,
"y": 440,
"wires": [
[
"e4faba0c.56b178"
]
]
},
{
"id": "5220938b.ddb934",
"type": "debug",
"z": "638c0f19.4d555",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "req",
"x": 280,
"y": 500,
"wires": []
},
{
"id": "6e29e3ac.0bd18c",
"type": "debug",
"z": "638c0f19.4d555",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 800,
"y": 600,
"wires": []
}
]
答案 0 :(得分:0)
提供它是您要发送的真实的.doc文件,则它应该可以工作。该代码正在寻找.json对象或文件缓冲区。 .doc
个文件将被视为缓冲区。我已经尝试了您的代码,并成功地将其加载到发现文档中,尽管文档加载的响应实际上在msg.document
而非msg.payload
上进行。