Hello i have an app using the MEAN stack. I am getting from my end point for getting images. the image array value is looking like :
8,8,7,7,9,8,9,8,9,8,9,9,8,8,8,8,7,9,7,7,9,10,16,13,8,8,16,9,7,8,12,33,14,15,1
when i try to read using angular it doesn't work and it show the same.
I decided to use this function to convert it to base 64 so i can read it.
so in my controller i wrote like that :
export class MainController {
constructor($http) {
'ngInject';
this.$http = $http;
this.getMessages();
this.getImages();
this.arrayBufferToBase64 = function(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
}
and this is my function :
getImages() {
var vm = this;
this.$http.get('http://localhost:5000/api/photo').then(function(result) {
vm.images = result.data;
console.log(result.data);
});
}
then in my front end angular page i am doing like that :
<img ng-src="data:image/png;base64,{{arrayBufferToBase64(image.img.data.data)}}" alt="" />
when i try to read my images like that . :
<img ng-src="{{image.img.data.data)}}" alt="" />
it show me error that it is binary
but then it still not working
can anybody help how i can read this images coming from my mongodb and my node api