# How to zip multiple files

**URL:** <https://discourse.nodered.org/t/how-to-zip-multiple-files/37105>\
**Category:** General\
**Created:** [7 December 2020 08:20 UTC](https://discourse.nodered.org/t/how-to-zip-multiple-files/37105 "2020-12-07T08:20:35Z")\
**Posts on this page:** 4\
**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:** [7 December 2020 08:20 UTC](https://discourse.nodered.org/t/how-to-zip-multiple-files/37105/1 "2020-12-07T08:20:35Z")

</div>

Hi,

I want to compress multiple files into one zip file:

 ![zip-folder-1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2eefb9a8872f5654f959b1d964c3221252f67965.png)

When reading the instructions of `zip` node, it seems to be able to do this with the input payload is **Array** , I tried it without understanding how input **filename** and **payload** are correct !?

 ![zip-folder-2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/dacdec09707fd18ce598d7f40d9422a22a58a21b.png)

```auto
[{"id":"db2e6476.273128","type":"file in","z":"aa5a77d3.21b528","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":1210,"y":2400,"wires":[["29eaaf6.381265"]]},{"id":"9cb5f8ae.f87fb8","type":"function","z":"aa5a77d3.21b528","name":"","func":"var arrFiles = [];\n\narrFiles.push('C:\\\\Temp\\\\Test\\\\File1.txt');\narrFiles.push('C:\\\\Temp\\\\Test\\\\File2.txt');\narrFiles.push('C:\\\\Temp\\\\Test\\\\File3.txt');\n\n//msg.filename = arrFiles.toString();\nmsg.arrFiles = arrFiles;\n\nreturn msg;","outputs":1,"noerr":0,"x":870,"y":2300,"wires":[["30b15e87.412962"]]},{"id":"2ced30c0.015fa","type":"inject","z":"aa5a77d3.21b528","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":2300,"wires":[["9cb5f8ae.f87fb8"]]},{"id":"d2f256d9.3a7c78","type":"split","z":"aa5a77d3.21b528","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":870,"y":2400,"wires":[["22656107.c3054e"]]},{"id":"22656107.c3054e","type":"change","z":"aa5a77d3.21b528","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":2400,"wires":[["db2e6476.273128"]]},{"id":"30b15e87.412962","type":"change","z":"aa5a77d3.21b528","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"arrFiles","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":2400,"wires":[["d2f256d9.3a7c78"]]},{"id":"e464d114.b7505","type":"zip","z":"aa5a77d3.21b528","name":"","mode":"compress","filename":"","outasstring":false,"x":830,"y":2500,"wires":[["2d2f0be2.c417b4"]]},{"id":"2d2f0be2.c417b4","type":"change","z":"aa5a77d3.21b528","name":"","rules":[{"t":"set","p":"filenameNew","pt":"msg","to":"$replace(filename,/^.*[\\\\\\/]/, '')\t","tot":"jsonata"},{"t":"change","p":"filename","pt":"msg","from":"filenameNew","fromt":"msg","to":"ZIP_NEW.zip","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1183.234375,"y":2495.25,"wires":[["de7cf02e.901ff"]]},{"id":"de7cf02e.901ff","type":"change","z":"aa5a77d3.21b528","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"\"C:\\\\Temp\\\\Test\\\\\" & msg.filename","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1390,"y":2500,"wires":[["69ffe535.eecedc"]]},{"id":"69ffe535.eecedc","type":"file","z":"aa5a77d3.21b528","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1130,"y":2600,"wires":[["8192bbdf.6cf858"]]},{"id":"29eaaf6.381265","type":"change","z":"aa5a77d3.21b528","name":"","rules":[{"t":"change","p":"filename","pt":"msg","from":"C:\\Temp\\Test\\","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1380,"y":2400,"wires":[["e464d114.b7505"]]},{"id":"8192bbdf.6cf858","type":"debug","z":"aa5a77d3.21b528","name":"msg","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1430,"y":2600,"wires":[]},{"id":"23f55ef0.5ed142","type":"join","z":"aa5a77d3.21b528","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":2500,"wires":[["e464d114.b7505"]]},{"id":"26b89ffb.7ba54","type":"join","z":"aa5a77d3.21b528","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":993.234375,"y":2535.25,"wires":[["2d2f0be2.c417b4"]]},{"id":"c11dbe74.ba0d8","type":"join","z":"aa5a77d3.21b528","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1270,"y":2640,"wires":[[]]}]

```

Please tell me.  
Thanks!

---

<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 December 2020 08:37 UTC](https://discourse.nodered.org/t/how-to-zip-multiple-files/37105/2 "2020-12-07T08:37:39Z")

</div>

No, it is not.

After you load each file you need to put its data into an object with the new zipped filename

e.g.

function node...

```auto
var filename_only = msg.filename.split("/").pop(); // << I am guessing file name is in msg.filename

var o = { 
  payload: msg.payload, //store file data in object.payload
  filename: filename_only
}

msg.payload = o;
return msg;

```

Then feed that into a JOIN node set to create an array.

The **final payload going into the ZIP** must be an array of objects, with each object having `filename` and `payload` - like this...

```auto
[ 
  {
    payload: [buffer,of,file,data],
    filename: "filename.txt"
  },  
  {
    payload: [another,buffer,of,file,data],
    filename: "a_different_filename.txt"
  }
]

```

---

<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:** [7 December 2020 14:32 UTC](https://discourse.nodered.org/t/how-to-zip-multiple-files/37105/3 "2020-12-07T14:32:22Z")

</div>

Done!  
@Steve-Mcl Thank you for your enthusiastic guidance!

---

<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 December 2020 14:32 UTC](https://discourse.nodered.org/t/how-to-zip-multiple-files/37105/4 "2020-12-21T14:32:26Z")

</div>

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