你好,我有一个应用程序使用MEAN堆栈。我从我的终点获取图像。图像阵列值看起来像:从缓冲区转换为基址64使用角度阅读
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
当我尝试使用的角度这是行不通的阅读,它表现出同样的。
我决定使用这个函数将它转换为64位,这样我就可以读取它。
所以在我的控制,我写这样的:
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);
}
}
,这是我的函数:
getImages() {
var vm = this;
this.$http.get('http://localhost:5000/api/photo').then(function(result) {
vm.images = result.data;
console.log(result.data);
});
}
然后在我的前端角页我做这样的:
<img ng-src="data:image/png;base64,{{arrayBufferToBase64(image.img.data.data)}}" alt="" />
当我尝试读取像这样的图像。 :
<img ng-src="{{image.img.data.data)}}" alt="" />
它给我的错误,这是二进制
但随后仍然没有工作
任何人可以帮助我如何可以读取该图片来自我的MongoDB的到来,我的节点API