我从MongoDB获取图像。现在我想通过代码将图像下载到我的系统。
从这段代码我得到的对象: $ scope.clickEvent = function(x){
var path = x.path.replace('uploads','');
$http({
method: 'GET',
url: $API_URL + path,
headers: {
"Authorization": $localStorage.currentUser.token
}
}).then(function (response) {
var file = new Blob([response.data], {type: 'application/Image'});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
console.log("Result: " + response.data);
});
};
答案 0 :(得分:0)
尝试将content-type
标题和responseType
添加到'blob'
$http({
method: 'GET',
url: $API_URL + path,
headers: {
'Content-Type': 'image/jpg', //content type set to image
'Authorization': $localStorage.currentUser.token
},
responseType: 'blob'
})