Node-red-contrib-zip corrupts on unzip

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?

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 then edit your post

Sorry, new to NodeRed and the forum.

[{"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":[]}]

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.

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

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.

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

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.

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

2 Likes

Excellent.

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