# \[SOLVED\]Download a file from Ninox into Node-RED (Windows)

**URL:** <https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149>\
**Category:** General\
**Created:** [7 July 2021 19:33 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149 "2021-07-07T19:33:02Z")\
**Posts on this page:** 9\
**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:** [7 July 2021 19:33 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/1 "2021-07-07T19:33:03Z")

</div>

I am trying to use the **node-red-contrib-ninox** plug-in to download a file from my Ninox database. This just works fine for getting records but when downloading a file Node-RED completly shuts down and I have to restart it on command line.

- running Node-RED v1.3.5 with Windows Server 2019
- using node-red-contrib-ninox -v0.99.11
- downloaded and tried the example flows of the plug-in
- set up the node the right way, because I can exchange record entries

There is not much information on google or its just refering to the node documentation inside the web interface which I already read.

I really hope someone can give me a helping hand or a hint how I could achieve this another way

cmd\>

```auto
7 Jul 21:45:27 - [info] Started flows
url https://api.ninoxdb.de/v1/teams/notsavetoshare/tables/L/records/23 headers {
  Authorization: 'Bearer notsavetoshare',
  'Content-Type': 'application/json'
}
url https://api.ninoxdb.de/v1/teams/notsavetoshare/tables/I/records/9 headers {
  Authorization: 'Bearer notsavetoshare',
  'Content-Type': 'application/json'
}
7 Jul 21:45:45 - [red] Uncaught Exception:
7 Jul 21:45:45 - Error: Command failed: mkdir -p tmpfiles/wgz9t4ldqm; curl --header "Authorization: Bearer maybenotsavetoshare" https://api.ninoxdb.de/v1/teams/notsavetoshare/tables/L/records/23/files/L23/it.pdf -o tmpfiles/wgz9t4ldqm/L23/it.pdf;
Syntaxfehler.

    at ChildProcess.exithandler (child_process.js:319:12)
    at ChildProcess.emit (events.js:375:28)
    at maybeClose (internal/child_process.js:1055:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 July 2021 19:36 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/2 "2021-07-07T19:36:05Z")

</div>

What does the command line show when node-red crashes. There will be vital clues that you could raise with the author to get it fixed.

Also, what node-red version and node js versions are you running?

---

<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:** [7 July 2021 19:50 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/3 "2021-07-07T19:50:10Z")

</div>

Thank you steve! yes I should have provided this information from the beginning and attached it to the main message

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 July 2021 20:02 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/4 "2021-07-07T20:02:22Z")

</div>

> [@tfuchs1987](#):
>
> `Command failed: mkdir -p tmpfiles/wgz9t4ldqm`

You should raise an issue on the repo.

However, you might be able to fix this by creating a folder `tmpfiles` and ensure node-red has permission to write to it.

---

<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:** [7 July 2021 20:15 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/5 "2021-07-07T20:15:15Z")

</div>

assuming `tmpfiles` should be created inside `User directory : \Users\USERNAME\.node-red` but nothing on the error log changes.

I think this is Windows related and the javascript should execute `mkdir -p tmpfiles\test & curl --header "Authorization: Bearer Secret-Ninox-API-KEY" https://api.ninoxdb.de/v1/teams/noonecares/tables/L/records/23/files/it.pdf -o tmpfiles/test/it.pdf`

I have never raised an issue to a repository ... where can I do that - sry super noob question

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 July 2021 21:54 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/6 "2021-07-07T21:54:16Z")

</div>

> [@tfuchs1987](#):
>
> I have never raised an issue to a repository ... where can I do that

There is a link to the repo on the npm & flows page.

> **[Issues · Malte Engelhardt / node-red-contrib-ninox · GitLab](https://gitlab.com/kurvenschubser1/node-red-contrib-ninox/-/issues)**
>
> GitLab.com

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [7 July 2021 22:18 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/7 "2021-07-07T22:18:42Z")

</div>

But it probably shouldn't be shelling out to curl anyway (which I'm 99.9% sure won't be installed on your windows machine either)

Edit:

Yep, big warning flags in the source:

```auto
          // TODO: use javascript instead of curl to download file
          // request.get({ url, headers }, responseHandlerFile);
          const exec = require('child_process').exec;
          const cmd = `mkdir -p ${tmpdir}; curl --header "Authorization: ${headers["Authorization"]}" ${url} -o ${fname};`;
          exec(cmd, (e, stdout, stderr) => {
            if (e instanceof Error) {
              throw e;
            }
            msg.pathname = fname;
            node.send(msg);

```

---

<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:** [7 July 2021 22:36 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/8 "2021-07-07T22:36:37Z")

</div>

You guys made my day! Thank you so much steve and hardillb!  
I was astonished myself that curl runs exactly the same way in Windows

In Linux you combine two commands with `COMMAND1;COMMAND2` but in Windows it should be `COMMAND1 & COMMAND2` . I adapted this in const cmd and adjusted the const tmpdir and fname to the Windows file system in the script

`\\.node-red\node_modules\node-red-contrib-ninox\ninox\ninox.js`

```auto

          const tmpdir = `C:\\Users\\USERNAME\\.node-red\\tmpfiles`;
          const fname = `${tmpdir}\\${msg.filename}`;
          url += `records/${nid}/files/${msg.filename}`;
          // TODO: use javascript instead of curl to download file
          // request.get({ url, headers }, responseHandlerFile);
          const exec = require('child_process').exec;
          const cmd = `mkdir -p ${tmpdir} & curl --header "Authorization: ${headers["Authorization"]}" ${url} -o ${fname} &`;

```

Node-RED is not shutting down anymore and the whole flow is running like a charm 🤸‍♂️

---

<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:** [21 July 2021 22:36 UTC](https://discourse.nodered.org/t/solved-download-a-file-from-ninox-into-node-red-windows/48149/9 "2021-07-21T22:36:41Z")

</div>

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