This request type is returning a JPEG/PNG directly an image. Instead we , should get a url to image.
please update it or let me know how to handle this response.
Thank you.
You can solve this problem by using ajax request as follow >>>>
function getImg (){
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.responseType = ‘arraybuffer’;
xhr.onload = function (e) {
if (this.readyState === this.DONE) {
var uInt8Array = new Uint8Array(this.response);
var i = uInt8Array.length;
var binaryString = new Array(i);
while (i–)
{
binaryString[i] = String.fromCharCode(uInt8Array[i]);
}
var data = binaryString.join(’’);
var base64 = window.btoa(data);
var src ="data:image/png;base64," + base64;
/* do something like : */ $('img').attr('src', src);
Hi,can anyone tell me how I can solve this problem by using Nodejs- axios request ?
You can solve this problem by using ajax request as follow >>>>
function getImg (){
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.responseType = ‘arraybuffer’;
xhr.onload = function (e) {
if (this.readyState === this.DONE) {
var uInt8Array = new Uint8Array(this.response);
var i = uInt8Array.length;
var binaryString = new Array(i);
while (i–)
{
binaryString[i] = String.fromCharCode(uInt8Array[i]);
}
var data = binaryString.join(’’);
console.log(src);
}
};
xhr.open(“GET”, “https://coronavirus-monitor.p.rapidapi.com/coronavirus/masks.php”, true);
xhr.setRequestHeader(“x-rapidapi-host”, “coronavirus-monitor.p.rapidapi.com”);
xhr.setRequestHeader(“x-rapidapi-key”, “xxxxxxxxxxxx your API”);
xhr.send(data);
}
getImg();
/* good luke 😉*/
Hi, ok I will do what you need. Thanks