react dropzone is accepting any file even with specific file mime types

I'm using react-dropzone to upload image files in my react app. I've defined mime types to only allow specific mime types but It's accepting every file and then I get this error:

Unhandled Rejection (TypeError): URL.createObjectURL: Argument 1 is not valid for any of the 1-argument overloads.

what am I doing wrong here?

const [imageBlobs, setImageBlobs] = useState([]);

const onDrop = useCallback(acceptedFiles => {
    setImageBlobs(acceptedFiles.map(file => Object.assign(file, {
      preview: URL.createObjectURL(file)
    })));
    output({
      imageFiles: acceptedFiles,
      imageBlob: URL.createObjectURL(acceptedFiles[0])
    });
}, [output]);

const {
  getRootProps,
  getInputProps,
  isDragActive,
  isDragAccept,
  isDragReject
} = useDropzone({
  onDrop,
  accept: 'image/jpeg, image/png'
});


Read more here: https://stackoverflow.com/questions/67932992/react-dropzone-is-accepting-any-file-even-with-specific-file-mime-types

Content Attribution

This content was originally published by parham06 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: