html5csv icon indicating copy to clipboard operation
html5csv copied to clipboard

CSV.begin('#someFileInput') doesn't work if the user has already chosen a file.

Open DrPaulBrewer opened this issue 9 years ago • 1 comments

The code in html5csv.js, currently function fromFile defined in lines 262-297 is designed to act as an event handler for a file input. To capture the file this handler needs to be attached before the user chooses a file.

But another use case is that there is a file input where the user has already chosen the file and we would like to read from it. The existing code doesn't handle this use case because the reading of the file is triggered by a change event on the file chooser input.

The current inability to process an already-selected file makes it impossible to check the filename or file extension chosen by the user before processing it. It is possible, for instance, to upload a .PNG image file instead of a .CSV file and the code will try to tease rows of text out of the binary data.

The docs for CSV.begin on the main page also don't currently explain these limitations.

The fix/enhancement is simply breaking the existing file reading routines into two routines. Also, provide an option to restrict the asynchronous version to only allow .csv files or files matching a regex.

DrPaulBrewer avatar Dec 13 '15 03:12 DrPaulBrewer

added note in begin docs near end of front page

DrPaulBrewer avatar Dec 13 '15 09:12 DrPaulBrewer