# Node-red-contrib-zip corrupts on unzip

**URL:** https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212
**Category:** General
**Created:** [24 May 2020 19:56 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212 "2020-05-24T19:56:25Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Jonvic1891](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jonvic1891](https://discourse.nodered.org/u/Jonvic1891)
#### Post date: [24 May 2020 19:56 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/1 "2020-05-24T19:56:25Z")

</div>

Im trying to Zip some photos so that i can send them via email but when i zip them and then unzip them the unziped file corrupts. When i open it the message states "Error interpreting JPEG image file (Not a JPEG file: starts with 0x5b 0x7b)"

the flow pics up a file called image.jpeg in the "/home/pi" directory zips it, unzips it and puts it in a new directory called "/home/pi/zip test". I am using node-red-contrib-zip.

and here is my flow

[{"id":"a27182f4.ca77c","type":"tab","label":"zipper","disabled":false,"info":""},{"id":"5a0d2a4e.a060d4","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":260,"wires":},{"id":"92139b8.82aee68","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":40,"wires":},{"id":"b09e59c7.b428f8","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":180,"wires":},{"id":"17221885.a1abc7","type":"inject","z":"a27182f4.ca77c","name":"","topic":"","payload":"/home/pi/download.jpeg","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":40,"wires":[["952a442b.c8d498"]]},{"id":"952a442b.c8d498","type":"file in","z":"a27182f4.ca77c","name":"","filename":"/home/pi/image.jpeg","format":"","chunk":false,"sendError":false,"encoding":"none","x":200,"y":120,"wires":[["92139b8.82aee68","dea8bc60.3eeb9"]]},{"id":"31b9d52f.0d484a","type":"zip","z":"a27182f4.ca77c","name":"","mode":"compress","filename":"","outasstring":false,"x":470,"y":180,"wires":[["b09e59c7.b428f8","87659d82.c8c35"]]},{"id":"87659d82.c8c35","type":"zip","z":"a27182f4.ca77c","name":"","mode":"decompress","filename":"","outasstring":false,"x":470,"y":260,"wires":[["5a0d2a4e.a060d4","91bd587.f3b4da8"]]},{"id":"dea8bc60.3eeb9","type":"change","z":"a27182f4.ca77c","name":"","rules":[{"t":"change","p":"filename","pt":"msg","from":"/home/pi/","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":120,"wires":[["1285d75c.eac9e9","31b9d52f.0d484a"]]},{"id":"1285d75c.eac9e9","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":120,"wires":},{"id":"4662fda2.299904","type":"file","z":"a27182f4.ca77c","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":470,"y":400,"wires":[["4fb57d60.efc264"]]},{"id":"4fb57d60.efc264","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":400,"wires":},{"id":"91bd587.f3b4da8","type":"change","z":"a27182f4.ca77c","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":""/home/pi/zip test/"& msg.filename","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":320,"wires":[["4662fda2.299904","5b2735b6.2ae2ec"]]},{"id":"5b2735b6.2ae2ec","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":320,"wires":}]

can anyone advise why the file gets corrupted?

---

<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: [24 May 2020 20:03 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/2 "2020-05-24T20:03:06Z")

</div>

Can you post a screenshot of your flow?

Also, in order to make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) then edit your post

---

<div class="post-metadata">

### Author: ![Jonvic1891](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jonvic1891](https://discourse.nodered.org/u/Jonvic1891)
#### Post date: [25 May 2020 20:37 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/3 "2020-05-25T20:37:40Z")

</div>

Sorry, new to NodeRed and the forum.

```auto
[{"id":"a27182f4.ca77c","type":"tab","label":"zipper","disabled":false,"info":""},{"id":"5a0d2a4e.a060d4","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":260,"wires":[]},{"id":"92139b8.82aee68","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":40,"wires":[]},{"id":"b09e59c7.b428f8","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":180,"wires":[]},{"id":"17221885.a1abc7","type":"inject","z":"a27182f4.ca77c","name":"","topic":"","payload":"/home/pi/download.jpeg","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":40,"wires":[["952a442b.c8d498"]]},{"id":"952a442b.c8d498","type":"file in","z":"a27182f4.ca77c","name":"","filename":"/home/pi/image.jpeg","format":"","chunk":false,"sendError":false,"encoding":"none","x":200,"y":120,"wires":[["92139b8.82aee68","dea8bc60.3eeb9"]]},{"id":"31b9d52f.0d484a","type":"zip","z":"a27182f4.ca77c","name":"","mode":"compress","filename":"","outasstring":false,"x":470,"y":180,"wires":[["b09e59c7.b428f8","87659d82.c8c35"]]},{"id":"87659d82.c8c35","type":"zip","z":"a27182f4.ca77c","name":"","mode":"decompress","filename":"","outasstring":false,"x":470,"y":260,"wires":[["5a0d2a4e.a060d4","91bd587.f3b4da8"]]},{"id":"dea8bc60.3eeb9","type":"change","z":"a27182f4.ca77c","name":"","rules":[{"t":"change","p":"filename","pt":"msg","from":"/home/pi/","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":120,"wires":[["1285d75c.eac9e9","31b9d52f.0d484a"]]},{"id":"1285d75c.eac9e9","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":120,"wires":[]},{"id":"4662fda2.299904","type":"file","z":"a27182f4.ca77c","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":470,"y":400,"wires":[["4fb57d60.efc264"]]},{"id":"4fb57d60.efc264","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":400,"wires":[]},{"id":"91bd587.f3b4da8","type":"change","z":"a27182f4.ca77c","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"\"/home/pi/zip test/\"& msg.filename","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":320,"wires":[["4662fda2.299904","5b2735b6.2ae2ec"]]},{"id":"5b2735b6.2ae2ec","type":"debug","z":"a27182f4.ca77c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":320,"wires":[]}]

```

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [25 May 2020 20:58 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/4 "2020-05-25T20:58:17Z")

</div>

Did you notice that, when unzipping, the output from the node is an array? In which case you need to move the buffer to the payload before passing to the file node. Also you have Append set in the file node so it will add to any existing file, if there is one. Better you use overwrite mode I think.

---

<div class="post-metadata">

### Author: ![Jonvic1891](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jonvic1891](https://discourse.nodered.org/u/Jonvic1891)
#### Post date: [25 May 2020 21:01 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/5 "2020-05-25T21:01:25Z")

</div>

thanks, how do I move the buffer to the payload from an array?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [25 May 2020 21:25 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/6 "2020-05-25T21:25:39Z")

</div>

With a Change node, Move ... To msg.payload. If you don't know how to get the path the buffer then have a look at the node red doc Working with Messages which will tell you how to get it from the debug node output.

---

<div class="post-metadata">

### Author: ![Jonvic1891](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jonvic1891](https://discourse.nodered.org/u/Jonvic1891)
#### Post date: [25 May 2020 21:28 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/7 "2020-05-25T21:28:38Z")

</div>

ive tried a change node to set msg.payload to msg.payload.0 but it brings the object with it rather than placing the data in the buffer

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed453a63daba2cb0ca2188dbdc98afe8fd5a5696.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [25 May 2020 21:32 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/8 "2020-05-25T21:32:56Z")

</div>

Do what I said, read the docs, use the debug node output to get the path (it isn't what you suggested) and use Move not Set (though it might work with Set, not sure).  
If it still doesn't work show us the debug output from the zip node, how you have configured the Change node and the debug output from the Change node.

---

<div class="post-metadata">

### Author: ![Jonvic1891](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jonvic1891](https://discourse.nodered.org/u/Jonvic1891)
#### Post date: [26 May 2020 12:26 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/9 "2020-05-26T12:26:58Z")

</div>

For future refference I used the change node to move msg.payload[0].payload to msg.payload and it worked

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [26 May 2020 12:56 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/10 "2020-05-26T12:56:59Z")

</div>

Excellent.

---

<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: [25 July 2020 12:57 UTC](https://discourse.nodered.org/t/node-red-contrib-zip-corrupts-on-unzip/27212/11 "2020-07-25T12:57:10Z")

</div>

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