-1

I want to display the number of lines a selected csv file is having before i upload it to express server. I am using multer for the uploading the file to server.

    <input type="file" name="data_file" id="name" required>

    <button type="button" onclick="confirm()"> Submit </button>

The follwing is the action to be taken once the button is clicked on

function confirm() {
    let fullPath = document.getElementById('name').value;
    let fileName = fullPath.replace(/^.*[\\\/]/, '');
    
    console.log(fileName.substring(fileName.lastIndexOf('/') + 1));
    document.getElementById("details").innerHTML = `
        <b> Data file: </b> ${fileName} <br>
         
        <br> <input type="submit" id="submit" value="Confirm Sendout"/>`;
    document.getElementsByClassName("confirm")[0].style.display = "block";

}
Ankita Basu
  • 51
  • 2
  • 10

1 Answers1

0

You need to parse the CSV file before processing. There are multiple libraries out in the market.

Adding a few references that might help:

https://stackoverflow.com/a/2953330/4545131

https://stackoverflow.com/a/12289296/4545131

  • Csv parsing can be done once the file has been uploaded already to the server. Is there any way to do the counting before the file is uploaded to the server. – Ankita Basu Aug 18 '22 at 11:19