我试图使用angularjs下载图像。在postman我得到输出为这种格式:
JFIF ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,锟锟锟锟锟锟<a id="download" ng-click="downloadfile()">Download FileName</a>
此代码用于下载图像。
$scope.downloadfile=function(){
var download = document.getElementById("download");
$scope.downloadData = 锟斤拷锟斤拷JFIF,,锟斤拷xPhotoshop 3.08BIM\gP53616c7465645f5fdfdda5a4f94df34e8d1d8e056e7e5dcc820ce57f793e13bfa39119fdc1b0c079锟斤拷C锟斤拷�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟�锟;
download.onclick = function() {
downloadFile("text.jpg", $scope.downloadData);
}
function downloadFile(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:image/jpeg;charset-utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
pom.click();
}
}
当我下载图像时,我将获得无效图像 提前致谢