Base64 encode/decode and download content generated in URL
base64, javascript
Solution
If you're still looking for an answer to this, check out my answer here. This is how I would adapt it for your needs.
// Convert the Base64 string back to text.
var txt = atob(data.reportBase64Bytes);
// Blob for saving.
var blob = new Blob([byteString], { type: "text/plain" });
// Tell the browser to save as report.txt.
saveAs(blob, "report.txt");
If you use this, make sure you grab the polyfills that I mention in the other post.
Problem
I am generating a string through JavaScript and I need to download it to a text file with a predefined dynamic filename. This way there will be no room for error by employees. This is obviously not possible in JavaScript due to security issues. However, from what I have read it should be possible with base64 encoding. I managed to encode the string and open a url with the decoded data. The string has been decoded successfully in this URL. The format is as follows: ``` var data = 'data:text/plain;base64,'+L_EncodedData; document.location = data; ``` I need to open a file dialog with the decoded data so the employees can download the content generated in this URL. Any help? Many thanks in advance