How to parse into base64 string the binary image from response?

I think part of the problem you’re hitting is that jQuery.ajax does not natively support XHR2 blob/arraybuffer types which can nicely handle binary data (see Reading binary files using jQuery.ajax). If you use a native XHR object with xhr.responseType=”arraybuffer”, then read the response array and¬†convert it to Base64, you’ll get what you want. Here’s a … Read more

how to display base64 encoded pdf?

for those who still can’t do it, i found this in someone else answer, but i don’t remember who… var objbuilder=””; objbuilder += (‘<object width=”100%” height=”100%” data=”https://stackoverflow.com/questions/40674532/data:application/pdf;base64,”); objbuilder += (myBase64string); objbuilder += (‘” type=”application/pdf” class=”internal”>’); objbuilder += (‘<embed src=”https://stackoverflow.com/questions/40674532/data:application/pdf;base64,”); objbuilder += (myBase64string); objbuilder += (‘” type=”application/pdf” />’); objbuilder += (‘</object>’); var win = window.open(“#”,”_blank”); var … Read more

React-Native: Convert image url to base64 string

I use rn-fetch-blob, basically it provides lot of file system and network functions make transferring data pretty easy. react-native-fetch-blob is deprecated import RNFetchBlob from “rn-fetch-blob”; const fs = RNFetchBlob.fs; let imagePath = null; RNFetchBlob.config({ fileCache: true }) .fetch(“GET”, “http://www.example.com/image.png”) // the image is now dowloaded to device’s storage .then(resp => { // the image path … Read more

How do I parse a data URL in Node?

Put the data into a Buffer using the ‘base64’ encoding, then write this to a file: var fs = require(‘fs’); var string = “data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==”; var regex = /^data:.+\/(.+);base64,(.*)$/; var matches = string.match(regex); var ext = matches[1]; var data = matches[2]; var buffer = Buffer.from(data, ‘base64’); fs.writeFileSync(‘data.’ + ext, buffer);