This is how you convert a base64 into binary stream
var base64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
fetch(base64)
.then(res => {
console.log(res.body instanceof ReadableStream)
})
Note: This only works in Blink atm, could use
Screw-FileReader and web-streams-polyfill to turn any blob into a
byte stream if you like
But what i really think you wanna do is to turn a base64 into a blob (binary container) and then upload it to a api as binary (not as base64) if that is true then this is just a duplicate of Creating a Blob from a base64 string in JavaScript and then it's just a mather of sending it with ajax to a server
var base64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
fetch(base64)
.then(res => res.blob())
.then(blob => {
console.log("here is your binary: ", blob)
// now upload it
fetch(api, {method: 'POST', body: blob})
})
Getting the base64 in the first place is really impractical and should be dealt with before using arrayBuffer, or blob
If you for example getting it from canvas - try using canvas.toBlob instead of toDataUrl
(data B)when you say that the api needs a binary stream - which one is it?