How to output file after unzip

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.

[{"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/","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!

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.

1 Like

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)

1 Like

@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_to_disk.json (1.8 KB)

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...

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

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.


Thank you for your enthusiastic guidance!

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

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!

    "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.


Thank you very much for providing more information to me!

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