Anyway for render() in mapping to return binary data?

Ok I'm feeling crazy today. Lately I've seen a bunch of HE projects that rely on cloud resources for "stupid" reasons (I want to display an image, I want to load a firmware file, etc.) I realized something. HE has a way to serve up local resources! you can create an App with a mappings {} section and return stuff using render(). I can set the content-type to application/octet-stream but it seems like I have to send a string (ascii/utf). If I send a byte[] it looks like it does .toString() and you just get [1,34,21...]. Is there anyway to send binary data back to the client? Here was my thought, basically make a small mapping that has a base64 string that represents a small image. then call decodeBase64 on it and send back the binary data. Then use the local API url to render it. Boom! File hosted on HE.

Thinking @chuck.schwer would be the expert to know if there a way to do it?

On my feature suggestion list would be if there was a place where we could store, I don't know 10MB of assets on the HE that'd be ideal, this was my crazy plan to try to do it given the tools we have!

1 Like

This would be a very neat feature to have... :slight_smile: The workarounds are a bit limiting...

Bumping this thread. There are a lot of projects asking for the Cloud endpoint to allow for passing a binary in the render call.

and of course here where @JustinL calls out it is not supported and Local only.

It is not a size limitation, you can 'kinda of' get an image to pass by using base64 encoding like so:

def img = "<img src='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAg...much more'/>"
def html = "<html><head><title>Embedded Image</title></head><body>${img}</body></html>"
render contentType: "text/html", data: html, status: 200 

but when doing a true binary image render

byte[] imageBytes = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, much more]
render contentType: "image/gif", data: imageBytes

This works with the local api but not cloud api. It seems to have problems with the byte[] length?

Tagging @bravenel since it looks like @chuck.schwer is no longer active for help.

1 Like

Noted. The usual "no promises" clause applies, but I'm looking at apps' cloud API interface.

Current implementation uses AWS MQTT, which has a hard limit of 128k on message size, so yeah.


Kewl, and understand the no promises. Here would be a small test use-case that returns a 5x5 pixel red dot. Works fine local, gets lost in the etherverse cloud endpoint.

render contentType: "image/png", data: img.decodeBase64(), status: 200

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.