Closed bartbutenaers closed 6 years ago
Hi @rikukissa,
The first of my 3 above questions is not valid. Did the test again and now it seems to be working fine:
Don't know what I did wrong in my previous test. So it works fine both with Buffers and base64 encoded strings!
Kind regards, Bart
Oh, good to hear it works! I was just about to start debugging this, but maybe I'll focus on the other issues you've created :) 100% appreciate your input. Keep it coming!
If the input is not correct, perhaps you can log an error or display a (red) node status. Because now you cannot see immediately if there is no input, or whether the input is incorrect...
Yup, you're absolutely right. It should be useful to get some feedback of why the node isn't working as expected. I'd imagine this would've also helped you when you came across your issue.
Perhaps you could also display something like this to make it very user friendly (but only a nice to have)
Totally! I actually found myself needing to fill in empty inputs with a transparent image Buffer while I was using this, which definitely isn't ideal.
Would you have time to drop me a PR addressing these things? Otherwise I can also fix these, but it might take me a while :)
Deal ;-) I will create a pull request for both items, but need some extra input:
I will display an error in the node status if the input is not correct. So the input needs to be a Buffer or a base64 encoded string ?? But when I look at your code the payload is always encoded to a base64 encoded string:
data: msg.payload.toString("base64")
However in my flow screenshot above, I have used a base64 encoder node. So the payload is base64 encoded twice: one time by the base64 encoder node, and once by your node. And it seems to work fine. Don't understand it at the moment ;-(
Need that information, to know what the input needs to be:
if ( !Buffer.isBuffer(msg.payload) && ?????????) {
node.error("Input should be a Buffer or a ??????????", msg);
node.status({fill:"red",shape:"ring", "Invalid input"});
}
Bart
Yep, I would say it's our safest bet to accept Buffers and base64 strings. According to my testing, you can call .toString('base64')
to a base64 string and it just returns the original base64 string, so that's probably not an issue and in that way caters for both allowed input types.
In your if statement, you could do something like this:
if ( !(Buffer.isBuffer(msg.payload) || (typeof msg.payload === 'string' && /some_regexp/.test(msg.payload)))) {
node.error("Input should be a Buffer or a ??????????", msg);
node.status({fill:"red",shape:"ring", "Invalid input"});
}
RegExp for checking if string is a valid base64 string: https://stackoverflow.com/a/8571649
About the 'no preview available' image:
I would maybe prefer using a constructed SVG element for telling the user there's no preview available rather than using a static image. Maybe we could for instance node.send data: null
back to the browser in cases where the msg.payload
doesn't pass our validation.
all 3 topics above are currently implemented in the different pull requests. I will close this issue, and discuss these items in their pull requests (if necessary).
Hi Riku,
Sorry to disturb you again.
Will first start with good news. When I use my node-red-contrib-multipart-stream-decoder node to get an MJPEG stream from my camera, your node still works great at 10 images per second:
But when I add your node directly behind my decoder node (which sends images as buffers) and before the base64 encoder, no image is displayed:
Some thoughts about this:
Perhaps you could also display something like this to make it very user friendly (but only a nice to have):
Now I will stop posting issues for today ;-)
Kind regards, Bart