0

I need to read a file locally using javascript. I know that for security reasons the possibility of doing this directly is inhibited. Is there any way to work around this? Furthermore, if I try to use the features of the File API specification, I can't get the "load" button to work if the button itself is not directly attached in the document.body. I would like this button to work even if attached to child type elements. Is there a solution for this?

Thank you very much

fileReader() {
    console.log("FileReader Called");

    var fileInput = document.getElementById('file');
    var fileDisplayArea = document.getElementById('source-container');

    fileInput.addEventListener('change', function(e) {
        var file = fileInput.files[0];
        var textType = /text.*/;

        if (file.type.match(textType)) {
            var reader = new FileReader();

            reader.onload = function(e) {
                fileDisplayArea.innerText = reader.result;
            }

            reader.readAsText(file);    
        } else {
            fileDisplayArea.innerText = "File not supported!";
        }
    });

}
VLAZ
  • 26,331
  • 9
  • 49
  • 67
AmiStack
  • 23
  • 7

0 Answers0