# Upload a file from Node-RED into Ninox

**URL:** <https://discourse.nodered.org/t/upload-a-file-from-node-red-into-ninox/49101>\
**Category:** General\
**Created:** [30 July 2021 02:32 UTC](https://discourse.nodered.org/t/upload-a-file-from-node-red-into-ninox/49101 "2021-07-30T02:32:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfuchs1987](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tfuchs1987/32/44508_2.png) [@tfuchs1987](https://discourse.nodered.org/u/tfuchs1987)\
**Post date:** [30 July 2021 02:32 UTC](https://discourse.nodered.org/t/upload-a-file-from-node-red-into-ninox/49101/1 "2021-07-30T02:32:31Z")

</div>

To upload data into the Ninox database I use the following msg.payload which works perfecly fine for strings but files are not properly uploading to the ninox image fields - at least with my attempts to provide the buffer object.

- node-red-contrib-ninox 0.99.11
- Node-RED v 2.0.3

```auto
msg.payload = [{
    id: flow.get('ninox-id'),
    fields: { "To": msg.header.to.text,
                "Subject": msg.topic,
                "Content": msg.html,
                "Cc" : msg.header.cc.text,
                "Date" : outDate,
//how to provide buffer and filename correct ? none of this works 
                "Attachment1" : msg.attachments[0],             
                "Attachment2" : msg.attachments[1].content,  
             }
}];

```

 ![ninoxupload2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a8b07eff7556b26e83ba2cafdfd9e15b25e52c7.png)  
 ![ninoxupload](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d26f29abd37b282b6598406dd9dff0d9260aa7fb.png)

I really hope someone can help me out since I cannot find any information on this and the documentation does not address how to handle files.

Thank you in advance for every reply!

---

<div class="post-metadata">

**Author:** ![tfuchs1987](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tfuchs1987/32/44508_2.png) [@tfuchs1987](https://discourse.nodered.org/u/tfuchs1987)\
**Post date:** [27 August 2021 13:51 UTC](https://discourse.nodered.org/t/upload-a-file-from-node-red-into-ninox/49101/2 "2021-08-27T13:51:00Z")

</div>

So I figured it out how to upload a file to the ninox api and the key is not to use the Ninox Contrib Node at all, because its broken! Also it uploads to the records file attchement tab not into a specific image field

My function-Node recieves a buffer in msg.payload from a file-in-Node and returns to a http-request-Node

```auto
msg.url = "https://api.ninoxdb.de/v1/teams/:teamid/databases/:databaseid/tables/:tableid/records/:recordid/files";
msg.method = "POST";
msg.headers = {"Authorization": "Bearer " + "YOUR-API-KEY-HERE",'Content-Type': "multipart/form-data"};

msg.payload = {
    'FormData' : {
        //Buffer from file-in-Node
        'value': msg.payload,
        'options': {
            'filename': "filename.pdf"
        }
    }};

```

A working flow to import as JSON:

```auto
[{"id":"46e2124ef0b032b9","type":"http request","z":"d773eee8.2943e","name":"POST Files","method":"use","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"bearer","x":870,"y":2420,"wires":[["2e9fa724e3a7e3a3"]]},{"id":"5494131661011d09","type":"function","z":"d773eee8.2943e","name":"","func":"nRecords = \"RECORD-ID\";\nnTables = \"TABLE-ID\";\nnDatabases = \"DATABASE-ID\";\nnTeams = \"TEAM-ID\";\nnAPI = \"https://api.ninoxdb.de/v1/teams/\";\napiURL = nAPI+nTeams+\"/databases/\"+nDatabases+\"/tables/\"+nTables+\"/records/\"+nRecords+\"/files/\";\n//https://api.ninoxdb.de/v1/teams/:teamid/databases/:databaseid/tables/:tableid/records/:recordid/files\n\nmsg.url = apiURL;\nmsg.method = \"POST\";\nmsg.headers = {\"Authorization\": \"Bearer \" + \"YOUR-API-KEY-HERE\",'Content-Type': \"multipart/form-data\"};\n\nmsg.payload = {\n 'FormData' : {\n //Buffer from file-in-Node\n 'value': msg.payload,\n 'options': {\n 'filename': \"filename.pdf\"\n }\n }};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":755,"y":2420,"wires":[["46e2124ef0b032b9"]],"icon":"font-awesome/fa-cloud-upload","l":false,"info":"////////////////////////////////////////////////////////////////////////////////////\n//Funktionstüchtiger Code!\nmsg.filename = \"Anhang3.pdf\";\nnRecords = \"23\";\nnTables = \"L\";\nnDatabases = \"ndvkova6gr27\";\nnTeams = \"jmv4Qv6D5X7kPsh7N\";\nnAPI = \"https://api.ninoxdb.de/v1/teams/\";\napiURL = nAPI+nTeams+\"/databases/\"+nDatabases+\"/tables/\"+nTables+\"/records/\"+nRecords+\"/files/\";//+msg.filename;\n//https://api.ninoxdb.de/v1/teams/:teamid/databases/:databaseid/tables/:tableid/records/:recordid/files/:filename\n//https://api.ninoxdb.de/v1/teams/jmv4Qv6D5X7kPsh7N/databases/ndvkova6gr27/tables/L/records/23/files/Anhang1.pdf\";\n\nflow.set('Ninox-API-Key-01', \"21354ea0-dc78-11eb-9129-1bb5351801b2\")\n\nmsg.url = apiURL;\nmsg.method = \"POST\";\nmsg.headers = {\"Authorization\": \"Bearer \" + flow.get(\"Ninox-API-Key-01\"),'Content-Type': \"multipart/form-data\"};\n\nmsg.payload = {\n 'FormData' : {\n 'value': msg.payload,\n 'options': {\n 'filename': msg.filename\n }\n }};\n\nreturn msg;\n////////////////////////////////////////////////////////////////////////////////////"},{"id":"121516c0c58b41ef","type":"inject","z":"d773eee8.2943e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":635,"y":2420,"wires":[["6a1e012078a5d140"]],"icon":"font-awesome/fa-power-off","l":false},{"id":"2e9fa724e3a7e3a3","type":"debug","z":"d773eee8.2943e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":975,"y":2420,"wires":[],"l":false},{"id":"6a1e012078a5d140","type":"file in","z":"d773eee8.2943e","name":"","filename":"./load/testfile/here.pdf","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":695,"y":2420,"wires":[["5494131661011d09"]],"l":false}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 September 2021 13:51 UTC](https://discourse.nodered.org/t/upload-a-file-from-node-red-into-ninox/49101/3 "2021-09-10T13:51:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
