I have to request a binary image from a server, but I need extra headers and authorization. Thus I can only do this on the backend. After I receive the image using ionic native HTTP, I’ve tried to display the image several times, but none worked.
1) I tried setting the binary data to a field like this:
this.unit.img(this.unitInfo.logo).then( (r) => {
this.logo = r.data;
}
And on html:
<ion-img [src]="logo"></ion-img>
2) I also tried converting the img to a base64 img, like this:
this.unit.img(this.unitInfo.logo).then( (r) => {
var imageData = btoa(r.data);
this.logo = "data:image/png;base64,"+imageData
And also:
<ion-img [src]="logo"></ion-img>
To display the image, but none of these works
Dont know if this is useful, but this is the code used to fetch the image:
make_get_img(path, options){
let headers = Object.assign({
'Accept': '*/*',
'Content-Type': '*/*'
}, options.headers || {})
if(this.token){
headers = Object.assign(headers, {
'token': this.token
})
}
let url = this.getUrlWithParams(path, options.urlParams)
return this.http.get(url, { responseType: 'blob' }, headers);
}
This is the console.log of the binary:
And the console.log of the base64 string:
I tested the string on other sites, and I get a message saying tthe conversion was wrong.
I dont know how to fix this.
Please help.