nzambello / react-csv-reader

React component that handles csv file input and its parsing
https://nzambello.github.io/react-csv-reader/
MIT License
199 stars 48 forks source link

validating csv file #42

Closed nzambello closed 3 years ago

nzambello commented 4 years ago

Hi guys, still got the same problem, it works correctly on Firefox, but with Chrome no.

I'm using ubuntu 18.04

Originally posted by @AmineBlel in https://github.com/nzambello/react-csv-reader/issues/9#issuecomment-602728899

nzambello commented 4 years ago

@AmineBlel which version on react-csv-reader are you using? Do you confirm that the issue is about the type of the files the browser allow you to load?

nzambello commented 4 years ago

@AmineBlel I just tested the demo on Chrome and it works correctly. Do you have the same issue with the demo on CodeSandBox?

AmineBlel commented 4 years ago

@nzambello, I'm using react-csv-reader 3.0.4, and yes with Chrome it gives me the chance to upload files with other extensions like pdf, but with Firefox, it shows just csv files to upload. even in the demo I have the same problem uploadIssue

brycepolly commented 4 years ago

I had to change the console.dir line to console.log to see the results in the demo

nzambello commented 4 years ago

The accept prop is mapped to the element, so it's basic HTML stuff. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file

If you read MDN docs, you'll see:

The accept attribute doesn't validate the types of the selected files; it simply provides hints for browsers to guide users towards selecting the correct file types. It is still possible (in most cases) for users to toggle an option in the file chooser that makes it possible to override this and select any file they wish, and then choose incorrect file types.

I tested on Chrome on Linux and using other browsers and OS, so I can guarantee that the default file type is csv, but the user is able to select other type of files by selecting different kind of filters like "All type of files".

exaucae commented 3 years ago

Hi, is there a workaround to enforce csv upload only?

nzambello commented 3 years ago

@chrys-exaucet take a look at #55 I'm merging and releasing that as soon as tests are fulfilled (and passing)

nzambello commented 3 years ago

@chrys-exaucet check https://github.com/nzambello/react-csv-reader/releases/tag/v3.3.0

exaucae commented 3 years ago

Thanks @nzambello, I 'll try it out ASAP.