Open CSV file and read its contents

0

I have the CSV file information in the console.log of the backend, I would need to access this file and read its contents, any tips?

This is the back-end code snippet that receives the file:

exports.anexo = function(req, res){

  var arquivo = req.files.uploads;
  var date = new Date();
  var dateTime = date.getTime();
  console.log(arquivo);

  var fileList = [];
    if(arquivo != undefined){
        for(var i=0; i < arquivo.length; i++){
            if(arquivo[i].originalFilename != undefined){
                var url_arquivo = dateTime + '_' + arquivo[i].originalFilename;
                var tipo_arquivo = arquivo[i].type;
                var path_origem = arquivo[i].path;
                var path_destino = './uploads/' + url_arquivo;

                var File = {
                    url_arquivo: url_arquivo
                };

                fileList.push(File);
            }
        }
    }
}

And here's the code part on the front end that reads the file and sends it back-end

anexaArquivos(fileList : File[]) : Promise<any> {
    console.log('chamou a função no regiao.service')
    return new Promise((resolve, reject ) => {
      let formData : FormData = new FormData()
      let xhr : XMLHttpRequest = new XMLHttpRequest()

      if(fileList.length > 0){
        for( let i = 0; i < fileList.length; i++){
          formData.append("uploads[]", fileList[i], fileList[i].name);
        }
      }
      xhr.onreadystatechange = function () {
          if (xhr.readyState === 4) {
              if (xhr.status === 200) {
                  resolve(JSON.parse(xhr.response))
              } else {
                  reject(xhr.response)
              }
          }
      }

      xhr.open('POST', '${SES_API}/regiao/importar', true);
      xhr.setRequestHeader('Authorization', 'Bearer ${this.userService.sessao.accessToken}');
      xhr.send(formData);
    })
  }
    
asked by anonymous 27.02.2018 / 12:51

1 answer

0

There is a stop called D3.js that will help you use data, you can use it by adding:

<script src="https://d3js.org/d3.v4.min.js"></script>

(hereisthegithublinkwithinformationaboutd3 link )

This is a very easy way, putting the line of src up after you only use it:

d3.csv(arquivo,funcao)

Where the filename is the filename with the final .csv and function is a function that you will create where you will execute what you want.

    
27.02.2018 / 18:32