0

In Node-RED, it has "Document uploder node", which sounds can upload file to Discovery Service, but, the problem is my client want to upload .doc file. Of course I tried, but Discovery service side treat the payload as json and cannot got expected result...

  • I attached Node-RED flow' json as js snippet, can reproduce the problem
  • Just FYI also attached the upload result Document upload result

Please let me know if some can help me ...

Thank you, Sincerely :)

[
    {
        "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": []
    }
]
Ken White
  • 123,280
  • 14
  • 225
  • 444
I.fuji
  • 1
  • 3

1 Answers1

0

Providing it is a real .doc file that you are sending, then it should work. The code is looking for either a .json object or a file buffer. .doc files will be seen as buffers. I have tried your code, and got it to successfully load a document into discovery, though the response from the document load actually goes on msg.document and not msg.payload.

chughts
  • 4,210
  • 2
  • 14
  • 27
  • Hi chughts-san Thank you for your comment :) I created a simple doc file , and then tried again , but still not gone well... [sample doc](https://ibm.box.com/s/3jtudqtnfjh1nxoizc2jt9eg0ffzkh8a) – I.fuji Jul 25 '18 at 05:33
  • As a sanity check try installing this package - https://flows.nodered.org/node/node-red-contrib-browser-utils, and making use of the file inject to send your .doc file as a file buffer into msg.payload. – chughts Jul 26 '18 at 09:12