I am creating a WEB application and need to read a txt file that will be provided by the user. The code I'm using to read is not working and I can not find a way to read it elsewhere.
// Código dentro do controller
$scope.imprimir = function () {
lerArquivoTxt.carregarArquivo();
}
// Código dentro do service
function _carregarArquivoTxt() {
var arquivoSelecionado = document.getElementById('arquivoPastas');
var divSaida = document.getElementById('textoLido');
var fileExtension = /text.*/;
var arquivoLeitura = arquivoSelecionado.files[0];
var fileReader = new FileReader();
fileReader.readAsText(arquivoLeitura);
divSaida.innerText = 'resultado: ' + fileReader.result;
}
<div class="col-sm-6 form-group" id="arquivo">
<div class="lbltitulo" for="Numero">Selecione o arquivo base para criar as pastas do projeto:</div>
<div class="tbpdd16">
<input type="file"
id="arquivoPastas"
class="hideBtn btn btn-warning">
</div>
<div class="">
<input type="text"
id="txtfiletoread"
class="form-control"
placeholder="Pasta / sub pasta"
ng-model="pasta.pasta">
</div>
<div id="textoLido"></div>
The idea is that the user select a file through the input file, the controller calls the function _loadTextTxt () from the service and this function read and return the whole file read. I need help with the code that reads the txt file.