I'm stucking on a problem that I cannot understand.
I got an HTML page, declaring <meta charset="utf-8" />, attempting to create and download a text file, containing some UTF8 characters.
The text is stored inside a JS variable and I'm trying to download the variable content as text file using the DataURI API.
This is the code:
const myText = "àòùè";
const uriContent = "data:text/plain;charset=utf-8;base64," + btoa(myText);
const element = document.createElement('a');
element.setAttribute('href', uriContent);
element.setAttribute('download', "example_filename.log");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
The resulting file is saved as ISO8859-15 and not in UTF-8 as declared in dataURI. It results in strange characters due to wrong encoding.
The encoding is checked using the file command under UNIX:
file example_filename.log
example_filename.log: ISO-8859 text