Just curious if its possible to display a generated image in the WebServerDAT? Using the default banana on the MovieFileIn TOP could I reference the image and host it on the web page?
With the Python function op(‘moviefilein1’).saveByteArray(‘jpg’) you can compress any top to be a JPG and send this as response to the webbrowser.
Thank you, I see it in the docs now. Now this doesn’t work, but am I looking to do something along these lines in the WebServer onHTTPRequest callback? (The HTML has a placeholder slug I’m looking to replace.) Or am I looking to connect to the WebSocket and send the byteArray to sendBinary?
html = op('webserver1').text
imageByteArray = op('moviefilein1').saveByteArray('JPG')
html = html.replace('{{IMAGE}}', '<img src="data:image/jpg;base64,' + imageByteArray.decode() + '"/>')
response['data'] = html
Jo Brent. That the wrong way. What you want to do is handle the request one after the other. The first request asks for the website. The seconds request asks for the image when the website is loaded by the browser.
So kinda like:
if request['uri'] == 'index.html':
response['data'] = op('index').text
elif request['uri'] == 'Image.jpg':
response['data'] = op('Image').saveByteArray('JPG')`
But this is pretty stiff and cant handle anything else. But this gets pretts comlicated for a forum post.
I built 5 bases for a workshop and part number 4 I think is a pretty solid basic HTTP-Server. Check it out here:
Thank you very much. I’ll dig into this tonight.
Hi,
Did you ever get your image appended into the img tag? I’ve tried several different ways but haven’t gotten it to work. I have gotten the image to appear or download, just not in through the tag.
Thanks!