Fetching Images via HTTP

695 views
Skip to first unread message

Matthew Boyle

unread,
Nov 17, 2014, 8:23:17 PM11/17/14
to node...@googlegroups.com
Hi folks, I'm new to Node-RED and I've come across a problem that I thought would be simple but is giving me some trouble. Basically, I want to fetch an image when visiting a specific page hosted within Node-RED. To do this I create an HTTP Input object and give it the URL "/input", then pass that msg off to an HTTP Request function that points to <whatever image's> URL. Then, I pass that result straight to an HTTP Response object. I thought that this would allow me to view <whatever image> from within the page (i.e. "localhost:1880/input"), but I seem to be getting back bad data. Is this issue a duplicate of https://github.com/node-red/node-red/issues/415, or am I simply doing something wrong?

Here's the flow JSON:

[{"type":"tab","id":"e1f477ee.1e0b88","label":"Sheet 1"},{"id":"67ad1ca7.9852e4","type":"http in","name":"URLInput","url":"/input","method":"get","x":177,"y":156,"z":"e1f477ee.1e0b88","wires":[["e49c792b.1b6388"]]},{"id":"828df426.7d7208","type":"http response","name":"URLOutput","x":951,"y":156,"z":"e1f477ee.1e0b88","wires":[]},{"id":"1bcf8ccf.e43073","type":"debug","name":"name2","active":true,"console":"false","complete":"false","x":949,"y":235,"z":"e1f477ee.1e0b88","wires":[]},{"id":"e49c792b.1b6388","type":"http request","name":"GetImage","method":"GET","url":"https://www.ibm.com/developerworks/community/blogs/B-Fool/resource/BLOGS_UPLOADED_IMAGES/Capture1b.JPG","x":564,"y":155,"z":"e1f477ee.1e0b88","wires":[["828df426.7d7208","1bcf8ccf.e43073"]]}]

Dave C-J

unread,
Nov 19, 2014, 6:47:53 PM11/19/14
to node...@googlegroups.com
Yes -  it's the same problem... - right now anything coming into http gets made into a utf-8 string - which corrupts binary images - same as 415. 
If we force it to binary then a lot of text based pages break...
We're one the way to fixing it - almost at top of the pile...

Luis Montes

unread,
Nov 19, 2014, 7:32:27 PM11/19/14
to node...@googlegroups.com
I'd recommend swapping out the npm request module you're using in the http node for cujo's rest.  You're already using when.js so its not much more overhead, and it's promise based :)

Rest.js uses interceptors which are a simple api for modifying requests and repsonses.


It recognizes json types and parses, as well as properly handling binary vs. text.

Luis

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages