I am receiving JSON response from the server, however using data URI has some common problems like length limitations not to mention security issues, etc.
Searching through, i have found some useful examples such as the createObjectURL and FileReader. However the images do not show.
So the blobs are base64 encoded and sent in JSON format. $json_array[]= base64_encode($flal_file);
In JavaScript, I do something like:
Attempt 1 (URL show in the source code but images do not show):
$(data).each(function(index,data){
var typedArray = data;
var blob = new Blob([typedArray.buffer], {type: 'application/octet-stream'});
var url = URL.createObjectURL(blob);
res = '<img src="'+url+'"/>';
});
Attempt 2 (getting undefined result):
const blb = new Blob(data, {type: "text/plain"});
const reader = new FileReader();
// This fires after the blob has been read/loaded.
reader.addEventListener('loadend', (e) => {
const text = e.srcElement.result;
console.log(text);
});
// Start reading the blob as text.
reader.readAsText(blb);
The browser cannot read the whole blob due to the length limitation. Perhaps i need to shorten the response from the server.