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