2017-05-26 60 views
0

我從MongoDB獲取圖像。現在我想通過代碼將圖像下載到我的系統中。從角度js下載圖像

從這個代碼我得到的對象: $ scope.clickEvent =功能(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); 


       }); 
      }; 

的Bt我收到下載的東西是: enter image description here

回答

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' 
    }) 
+0

得到了答案。謝謝。 –