Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate file type on Drop #110

Open
Angelfire opened this issue Dec 21, 2021 · 1 comment
Open

Validate file type on Drop #110

Angelfire opened this issue Dec 21, 2021 · 1 comment

Comments

@Angelfire
Copy link

accept attribute only works if you try to upload a file using the input HTML element, but if you try to drop an image/png the CSVReader doesn't throw an error, the validation can be made easily:

const typeAccepted = 'text/csv, .csv, application/vnd.ms-excel';

const handleDrop = (e) => {
    e.preventDefault();
    e.stopPropagation();
    
    const [file] = e.dataTransfer.files;

    if (file.type && typeAccepted.includes(file.type)) {
      // do something
    } else {
      console.error(`File type ${file.type} is not accepted`);

      return false;
    }
}

I would love to be able to submit a PR but I have no idea about TS

@Angelfire
Copy link
Author

Does anyone pay attention to these issues? c.c. @Bunlong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant