Mustache Template Buffer Out

Hi all,

I'm using an HTML code through mustache template node, as below:

image

The Idea is to get a "true" and complete buffer output in the first "1-string buffer" debug node, as in the second debug node "2-Buffer".
The problem is that the template node "image" outputs only text of the code itself, and not the smiley image as in the HTTP out: "http://127.0.0.1:1880/myimage"

Here's the flow:

[{"id":"474e4db9.c11e94","type":"http in","z":"8561fce.5cad2","name":"","url":"/myimage","method":"get","upload":false,"swaggerDoc":"","x":120,"y":980,"wires":[["737221c3.4437b"]]},{"id":"737221c3.4437b","type":"template","z":"8561fce.5cad2","name":"image","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n<body>\n\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png\" alt=\"Smiley face\" width=\"42\" height=\"42\">\n\n</body>\n</html>\n","output":"str","x":290,"y":960,"wires":[["d92586c.c839478","20e0cbad.f8b604"]]},{"id":"d92586c.c839478","type":"http response","z":"8561fce.5cad2","name":"","statusCode":"","headers":{},"x":430,"y":920,"wires":[]},{"id":"f412297d.781dc8","type":"debug","z":"8561fce.5cad2","name":"1-String-Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":980,"wires":[]},{"id":"20e0cbad.f8b604","type":"http request","z":"8561fce.5cad2","name":"Post","method":"POST","ret":"bin","paytoqs":false,"url":"http://localhost:1880/myimage","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":980,"wires":[["f412297d.781dc8"]]},{"id":"557afc7e.efcdd4","type":"http request","z":"8561fce.5cad2","name":"GET","method":"GET","ret":"bin","paytoqs":false,"url":"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":1060,"wires":[["71f86078.01758"]]},{"id":"71f86078.01758","type":"debug","z":"8561fce.5cad2","name":"2-Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":480,"y":1060,"wires":[]},{"id":"aa00b974.31ada8","type":"inject","z":"8561fce.5cad2","name":"Inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1060,"wires":[["557afc7e.efcdd4"]]},{"id":"4987c6b8.bf43d8","type":"inject","z":"8561fce.5cad2","name":"Inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":920,"wires":[["737221c3.4437b"]]}]

It seems simple, but I'm struggling with it for hours.
Any comment and idea is highly appreciated. Thanks!
.

Hi @gilad

I'm struggling to understanding what you are trying to do here.

What I can see is you have a flow (the top one) that responds to an HTTP GET request to /myimage with some HTML content that includes an <img> element with a src attribute pointed at an image hosted on wikimedia. That flow also sends that HTML as an HTTP POST to /myimage - but there is no flow here configured to handle that.

The second flow does an HTTP GET of the image from wikimedia.

You say you want the Debug output of 1-String-Buffer to be the same as 2-Buffer - but they are doing completely different things. The 1-String-Buffer debug node will show the response of the Post node, but without seeing what flow you have configured to handle that, I can't say what it will output.

Hello @knolleary,

Thanks for the prompt response.

I'm trying to get the first flow result "1-String Buffer" debug node,
( msg.payload : buffer[147] )

image

[{"id":"474e4db9.c11e94","type":"http in","z":"8561fce.5cad2","name":"","url":"/myimage","method":"get","upload":false,"swaggerDoc":"","x":120,"y":980,"wires":[["737221c3.4437b"]]},{"id":"737221c3.4437b","type":"template","z":"8561fce.5cad2","name":"image","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n<body>\n\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png\" alt=\"Smiley face\" width=\"42\" height=\"42\">\n\n</body>\n</html>\n","output":"str","x":290,"y":960,"wires":[["d92586c.c839478","20e0cbad.f8b604"]]},{"id":"d92586c.c839478","type":"http response","z":"8561fce.5cad2","name":"","statusCode":"","headers":{},"x":430,"y":920,"wires":[]},{"id":"f412297d.781dc8","type":"debug","z":"8561fce.5cad2","name":"1-String-Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":980,"wires":[]},{"id":"20e0cbad.f8b604","type":"http request","z":"8561fce.5cad2","name":"Post","method":"POST","ret":"bin","paytoqs":false,"url":"http://localhost:1880/myimage","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":980,"wires":[["f412297d.781dc8"]]},{"id":"4987c6b8.bf43d8","type":"inject","z":"8561fce.5cad2","name":"Inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":920,"wires":[["737221c3.4437b"]]}]

to be identical to the second flow result - 2-Buffer debug node
( msg.payload : buffer[11279] )

image

[{"id":"557afc7e.efcdd4","type":"http request","z":"8561fce.5cad2","name":"GET","method":"GET","ret":"bin","paytoqs":false,"url":"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":1060,"wires":[["71f86078.01758"]]},{"id":"71f86078.01758","type":"debug","z":"8561fce.5cad2","name":"2-Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":480,"y":1060,"wires":[]},{"id":"aa00b974.31ada8","type":"inject","z":"8561fce.5cad2","name":"Inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1060,"wires":[["557afc7e.efcdd4"]]}]

They both should represent the buffer output of this wikimedia image url example
for further analysis and (also for Base64 conversion) , but the "1-String Buffer" debug node obviously returns only the buffer/string of the HTML code itself and not the image, as it will be in HTTP OUT node.

The question is how it's possible to mimic the behavior of the second flow 2-Buffer for the first flow "1-String Buffer" so the outputs will be identical.

Thanks!

The flows are doing fundamentally different things.

The first flow is generating HTML that will be returned to your browser and your browser will load the image. The flow doesn't ever get the image data itself.

The second flow is getting the image directly.

If you want the first flow to return the image data directly, why not do it in the same way as the second flow using the HTTP Request node?

1 Like