50
rated 0 times
[
52]
[
2]
/ answers: 1 / hits: 15223
/ 5 Years ago, wed, july 17, 2019, 12:00:00
I get a byte[]
file from my server with the content of a file. I know the name and the content-type
. So far I have tried the following for downloading the file:
const a = document.createElement('a');
document.body.appendChild(a);
a.style.display = 'none';
const file = new Blob([content], {type: 'text/plain'});
const url = window.URL.createObjectURL(file);
a.href = url;
a.download = test.txt;
a.click();
window.URL.revokeObjectURL(url);
But this solution just downloads a text file with the binary content in it. How can I convert the binary data to the correspondent file type in the client side using JavaScript/Typescript? Thanks!
More From » angular