# How to output file after unzip

**URL:** <https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322>\
**Category:** General\
**Created:** [1 September 2020 22:07 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322 "2020-09-01T22:07:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [1 September 2020 22:07 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/1 "2020-09-01T22:07:31Z")

</div>

I use the **zip** node with _Decompress_ mode and the output is an array with objects containing filename as a String and payload as a Buffer.

 ![zip_decompress](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d52403b1cbd2886499278d1eab1a7f21216588f.png)

```auto
[{"id":"bb43c18.ca6614","type":"inject","z":"3b501765.6a7958","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":990,"y":3280,"wires":[["548c69f2.0bd0a8"]]},{"id":"548c69f2.0bd0a8","type":"file in","z":"3b501765.6a7958","name":"","filename":"/Temp/FOLDER.zip","format":"","chunk":false,"sendError":false,"encoding":"none","x":1170,"y":3280,"wires":[["d463fe35.49bab"]]},{"id":"d463fe35.49bab","type":"zip","z":"3b501765.6a7958","name":"","mode":"decompress","filename":"","outasstring":false,"x":1130,"y":3400,"wires":[["785fef4f.98257"]]},{"id":"785fef4f.98257","type":"debug","z":"3b501765.6a7958","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1290,"y":3400,"wires":[]}]

```

Is it possible to output the unzip result to a specified path?  
I tried searching on Node-RED's library with output keyword, but there was no result.

If possible, please tell me!  
Thanks.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [1 September 2020 23:01 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/2 "2020-09-01T23:01:48Z")

</div>

What is the full name of the zip node you are using? It will be something like node-red-contributes-??????

It looks like that zip contains two jpegs each in msg.payload. You can use the `split` node to separate the msg into parts then process each separately and do what you want with them.

You could then use a `file-outs node to put the result where you want.

---

<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:** [2 September 2020 00:21 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/3 "2020-09-02T00:21:35Z")

</div>

> [@minhhn0205](#):
>
> Is it possible to output the unzip result to a specified path

Yes. Use the file node to write the buffer to disk.

As it's an array, you should use the split node to make individual payloads and set the filename / move the buffer to payload before sending to file node.

Give it a go, use plenty of debug nodes, see how far you get, come back if you get stuck and show us where it fails (screenshots of flow and debug messages / export of flow etc)

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [2 September 2020 02:49 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/4 "2020-09-02T02:49:47Z")

</div>

@zenofmud, @Steve-Mcl Thank you for your support!  
The full name of the node I'm using is _node-red-contrib-zip_.  
I used `split` node and `file out` node but I still can't output the file to disk,  
i don't know where is going wrong...

 ![unzip_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3bf73ba5587404818dc52d016884fa1b2ccdfbcc.png) [unzip\_to\_disk.json](https://discourse.nodered.org/uploads/short-url/v5WHi7EDBGknw5PrfrnKqeXDSYV.json) (1.8 KB)

---

<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:** [2 September 2020 08:23 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/5 "2020-09-02T08:23:50Z")

</div>

Hi again,

so before anything else, it is far better if you post your flow like this...

`````  
`paste flow between back ticks`  
`````

(saves on downloading a file and can be viewed in the browser)

On to your issue.

So this is what the built in help for the file node says...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/757f6af338b2e04ad7e3d0f8580374af9469615d.png)

As you can see from your screenshot, you are sending a `payload` which is an object containing `filename` and `payload`.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4119e33202e4106d611412e9da276c601ec9e9fb.png)

In other words,

- your file name is in `msg.payload.filename` when it needs to be in `msg.filename`
- your file data is in `msg.payload.payload` when it needs to be in `msg.payload`

To fix this, insert a change node BEFORE the file node and move `msg.payload.filename` to `msg.filename` and then move `msg.payload.payload` to `msg.payload`

Last note: Do you really want to write the file to `/temp/output/folder/xxx.yyy`? If not, you might want to add a function node to re-format/re-calculate a better file name or path.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [2 September 2020 09:24 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/6 "2020-09-02T09:24:35Z")

</div>

Hi,  
Thank you for your enthusiastic guidance!

Because I did not understand how the node works, it was difficult...  
I have done it.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 September 2020 09:27 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/7 "2020-09-02T09:27:11Z")

</div>

Note of warning about node-red-contrib-zip:  
In macOS I created a flow `input` -\> `zip` (set to compress) -\> `zip` (set to decompress output as string) -\> `file-out` where the input file was a text file containing 'Hello World' (11 bytes long)

The output file is 253 bytes long and is a object!

```auto
[
  {
    "filename" : "/Users/",
    "payload" : ""
  },
  {
    "filename" : "/Users/Paul/",
    "payload" : ""
  },
  {
    "filename" : "/Users/Paul/temp/",
    "payload" : ""
  },
  {
    "filename" : "/Users/Paul/temp/input/",
    "payload" : ""
  },
  {
    "filename" : "/Users/Paul/temp/input/test-input.txt",
    "payload" : "Hello World"
  }
]

```

As you can see, the output is an array of objects where the last occurance of the array is an object with a 'filename' and a 'payload' and the payload is 'Hello World'

The node hasn't been updated in almost three years.

[EDIT] - I just tested on a Pi and it has the same problem.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [3 September 2020 00:14 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/8 "2020-09-03T00:14:09Z")

</div>

> [@zenofmud](#):
>
> As you can see, the output is an array of objects where the last occurance of the array is an object with a 'filename' and a 'payload' and the payload is 'Hello World'
> 
> The node hasn't been updated in almost three years.
> 
> [EDIT] - I just tested on a Pi and it has the same problem.

Thank you very much for providing more information to me!

---

<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:** [17 September 2020 00:14 UTC](https://discourse.nodered.org/t/how-to-output-file-after-unzip/32322/9 "2020-09-17T00:14:10Z")

</div>

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