I noticed that there is a difference when using Content-Type audio/wav
instead of application/cbor
.
When using audio/wav
the buffer send is also received as a buffer by the http in node.
When using application/cbor
the buffer send is received as a string in the http in node.
Here below the test flow demonstrating the difference:
[{"id":"c8a363d6.9d7ea","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"57f23b8e.96c0d4","type":"inject","z":"c8a363d6.9d7ea","name":"test2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["472840dc.7cc27"]]},{"id":"f213a3fd.a5656","type":"http request","z":"c8a363d6.9d7ea","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"http://localhost:1880/test1","tls":"","persist":false,"proxy":"","authType":"","x":310,"y":300,"wires":[["d3095d49.e1207"]]},{"id":"c0f4f4ca.6987e8","type":"http in","z":"c8a363d6.9d7ea","name":"","url":"/test1","method":"post","upload":false,"swaggerDoc":"","x":290,"y":460,"wires":[["b91f8f18.38633","538a872.9174b78","73a5dd8e.eeb734"]]},{"id":"b91f8f18.38633","type":"http response","z":"c8a363d6.9d7ea","name":"","statusCode":"","headers":{},"x":560,"y":460,"wires":[]},{"id":"d3095d49.e1207","type":"debug","z":"c8a363d6.9d7ea","name":"http request response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":600,"y":300,"wires":[]},{"id":"538a872.9174b78","type":"debug","z":"c8a363d6.9d7ea","name":"received message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":460,"y":420,"wires":[]},{"id":"bed7e6e9.97b918","type":"function","z":"c8a363d6.9d7ea","name":"set payload to buffer","func":"msg.payload = Buffer.from('00ff', 'hex');\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":220,"wires":[["8ea5db8c.5d44c8","243e5dfa.00aa12","f213a3fd.a5656"]]},{"id":"243e5dfa.00aa12","type":"debug","z":"c8a363d6.9d7ea","name":"http request in","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":260,"wires":[]},{"id":"73a5dd8e.eeb734","type":"function","z":"c8a363d6.9d7ea","name":"","func":"msg.payload = msg.payload.toString('hex');\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":520,"wires":[["350dd73e.bc2168"]]},{"id":"350dd73e.bc2168","type":"debug","z":"c8a363d6.9d7ea","name":"payload (received) in hex format","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":660,"y":520,"wires":[]},{"id":"8ea5db8c.5d44c8","type":"function","z":"c8a363d6.9d7ea","name":"","func":"msg.payload = msg.payload.toString('hex');\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":220,"wires":[["ba52257d.b84c58"]]},{"id":"ba52257d.b84c58","type":"debug","z":"c8a363d6.9d7ea","name":"payload (being send) in hex format","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":810,"y":220,"wires":[]},{"id":"7dda9258.f6379c","type":"change","z":"c8a363d6.9d7ea","name":"set msg.headers - content-type audio/wav","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"Content-Type\":\"audio/wav\",\"x-label\":\"idle\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":100,"wires":[["bed7e6e9.97b918"]]},{"id":"33da16dd.9c0e9a","type":"inject","z":"c8a363d6.9d7ea","name":"test1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["7dda9258.f6379c"]]},{"id":"472840dc.7cc27","type":"change","z":"c8a363d6.9d7ea","name":"set msg.headers - content-type application/cbor","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"Content-Type\":\"application/cbor\",\"x-label\":\"idle\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":140,"wires":[["bed7e6e9.97b918"]]}]
So clicking on test1 gives the expected result:
Clicking on test2 doesn't give the expected result: