Base64 encodes / decodes and downloads content generated in the URL

I am generating a string via JavaScript, and I need to load it into a text file with a predefined dynamic file name. Thus, employees will not have room for mistakes.

This is clearly not possible in JavaScript due to security issues. However, from what I read, it should be possible with base64 encoding.

I managed to encode a string and open url with decoded data. The string has been successfully decrypted at 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 decoded data so that employees can download the content created in this URL.

Any help?

Thank you very much in advance

+3
source share
2 answers

, . .

// 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");

, , , .

+3

.

window.OpenWindowForBase64 = function(url, callback) {
    var image = new Image();
    image.src = url;
    var w = window.open("");
    w.document.write(image.outerHTML);
    if (callback) {
        callback(url);
    }
}
0

All Articles