/    Sign up×
Community /Pin to ProfileBookmark

Convert Binary Stream into Image

I am attempting to convert what I believe is called a ‘binary stream’ into a recognizable image file. I am accessing this from a html page, the source is something along the lines of:

<img src=”127.0.0.1/image_files/?cmd=get-image;generate=-177991679;ctype=0;p=”></img>

I know that the file is displayed in the browser as a JPG, but given that I do not have a 127.0.0.1/image_files/blah blah.jpg URL I do not know how to convert this. I am using Nodejs. I have read about buffers, blob, etc, but nothing has worked. Are these called ‘Binary Streams’?

Many thanks
Trav

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NachfolgerJan 20.2020 — @travaris#1613327

I believe you will need to fetch the binary string, base64 encode it, then set it as the image SRC.

Per the stackoverflow question ([Source](https://stackoverflow.com/questions/14915058/how-to-display-binary-data-as-image-extjs-4)) the following code should work.

HTML
``<i>
</i>&lt;img id="binary-image" src="/" alt="Loading"&gt;&lt;/img&gt;<i>
</i>
`</CODE>

JavaScript
<CODE>
`<i>
</i>function getBinaryImage();
let request = new XMLHttpRequest();
let url = "//127.0.0.1/image_files/?cmd=get-image;generate=-177991679;ctype=0;p=";

// Attributes
request.onreadystatechange = function() {
// Checks
if (request.readyState !== 4) { return false }
if (request.status !== 200) { return false }

// UI
document.getElementById('binary-image').src = 'data:image/jpeg;base64,' + btoa(request.responseText);
}

// Submit
request.open('GET', url, true);
request.send();
}

getBinaryImage();<i>
</i>
``
×

Success!

Help @travaris spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...