Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  101] [ 7]  / answers: 1 / hits: 6322  / 10 Years ago, tue, march 11, 2014, 12:00:00

I want to download a file with angularjs (1.0.8) from a service Spring. I use a POST request because I have to pass a piece of HTML as parament, and browsers have limitation with length of query string. Here my code:



    $http({
method: 'POST',
url: '/export/pdf',
data: html= + graphHtml.outerHTML,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformResponse: function(data, headersGetter){
return data;
}
}).success(function(data) {
console.log(Type ' + typeof(data) + ');
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:application/pdf,' + data;
hiddenElement.target = '_blank';
hiddenElement.download = 'myFile.pdf';
hiddenElement.click();
});


I notice that the data received is already in string format! I see many (?) question point, and when type



    typeof(data)


i receive string. I don't want this interpretation of my raw data. When i try to write data in a file, the size is double respect original file! I know it is for string interpretation of binary data that instead wanted read as binary. Has anyone a solution for see data in raw format and not as string?


More From » angularjs

 Answers
4

set $http responseType in during config. and do something like this


[#46952] Tuesday, March 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyasiaalmap

Total Points: 294
Total Questions: 107
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
;