Add primitive check for file encoding when a file is uploaded and warn

if it's not UTF-8

Close #8
This commit is contained in:
2022-11-28 14:27:46 +01:00
parent f5ea1f850a
commit 20810aa850
9 changed files with 32 additions and 15 deletions

View File

@ -553,7 +553,8 @@ class CsvxmlPage {
uploadFileForValidation(file) {
const reader = new FileReader();
reader.readAsText(file);
let utf8 = true;
reader.readAsText(file, utf8 ? 'UTF-8' : 'CP1251');
let app = this;
@ -563,6 +564,13 @@ class CsvxmlPage {
function handleValidation() {
(async function() {
const result = reader.result;
if (utf8 && result.includes('<27>')) {
window.alert('The file encoding appears to not be UTF-8!\n\nTry exporting the file using the format "CSV (UTF-8)" if you use MS Excel or set the encoding to UTF-8 when exporting through LibreOffice!');
}
})();
// On loading success, check if the upload is valid JSON
console.log("Read file");
// Validate the file