admin管理员组文章数量:1327945
I'm using a method to download a CSV file from a Base64.
var dlnk = document.getElementById("myDownloadButton");
dlnk.href = 'data:application/octet-stream;base64,' + myBase64;
dlnk.click();
It worked until I realized that when the base64 is too long, I have a problem. It will open a white page and it won't download my CSV file. I think it's because my base64 is too long.
Do you have an alternative in JavaScript or in Symfony 3?
Thank you
I'm using a method to download a CSV file from a Base64.
var dlnk = document.getElementById("myDownloadButton");
dlnk.href = 'data:application/octet-stream;base64,' + myBase64;
dlnk.click();
It worked until I realized that when the base64 is too long, I have a problem. It will open a white page and it won't download my CSV file. I think it's because my base64 is too long.
Do you have an alternative in JavaScript or in Symfony 3?
Thank you
Share Improve this question asked Mar 27, 2018 at 10:32 FascoFasco 2431 gold badge3 silver badges18 bronze badges 3- 1 Instead of creating a data URL from the data, create a Blob Object. This will avoid the 33% extra overhead of base64 encoding. – georgeawg Commented Mar 27, 2018 at 11:04
- Example here with Blob Object stackoverflow./questions/19327749/… – GramThanos Commented Mar 27, 2018 at 12:18
- Thank you for your answers but it doesn't work with a large base64 (length more than 3472174 characters) – Fasco Commented Mar 27, 2018 at 12:28
1 Answer
Reset to default 7The solution:
let csvContent = atob("YOUR BASE64");
var blob = new Blob([csvContent], {type: "data:application/octet-stream;base64"});
var url = window.URL.createObjectURL(blob);
// you need to precise a front-end button to have a name
var dlnk = document.getElementById(nameFile);
dlnk.href = url;
dlnk.click();
本文标签: angularjsDownload a CSV file in Javascript (or Symfony) from a Base64Stack Overflow
版权声明:本文标题:angularjs - Download a CSV file in Javascript (or Symfony) from a Base64 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742217061a2434762.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论