react-papaparse icon indicating copy to clipboard operation
react-papaparse copied to clipboard

Validate file type on Drop

Open Angelfire opened this issue 4 years ago • 1 comments

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 avatar Dec 21 '21 14:12 Angelfire

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

Angelfire avatar Jan 31 '22 14:01 Angelfire