react-dropzone: [BUG] `accept` ignores extensions when used with wildcards
Describe the bug
Using a wildcard for image/* and then declaring file extensions doesn’t seem to work as expected in Firefox and Brave/Chrome.
The following code will let users drop any image type and the jpeg/png file extensions are ignored.
Note (and this is almost more important as we don’t need to react to drop events): The same behaviour can be observed when the file picker dialog opens, it will allow picking other image extensions, not just jpeg and png.
useDropzone({
accept: {
'image/*': ['.jpeg', '.png']
}
})
To Reproduce
Steps to reproduce the behavior:
- Go to https://react-dropzone.js.org/#section-accepting-specific-file-types
- Scroll to the 2nd example in the Browser limitations section (the one that “works”).
- Drag a webp, jpg, gif, heic, heif file onto it
- See “all files will be accepted” message
Expected behavior
Should only accept jpeg and png.
The desired behaviour can be achieved by using multiple MIME types matching their extension:
useDropzone({
accept: {
'image/png': ['.png'],
'image/jpeg': ['.jpeg'],
}
})
or leaving out the MIME type entirely (which doesn’t seem to work on Windows as it reverts back to “All files (.)), unless FsAccess is disabled”:
useDropzone({
accept: {
'': ['.png', '.jpeg'],
}
})
See: https://codesandbox.io/s/react-dropzone-example-forked-qcic4f?file=/src/App.js
Screenshots

Desktop (please complete the following information):
- OS: macOS 11.6.8
- Browser: Brave v1.41.100
- Version react-dropzone@14.2.2
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 10
- Comments: 16
It would have been very helpful if the library accept a more generic data structure for accept, one I can think of is:
This way, you can specify a specific extension without the need to specify the whole
mimetype, for example when I want only.jpgand.jpegfiles, I shouldn’t need to specifyimage/jpegbecause this makes the input to accept every file extension that have theimage/jpegmimetype, for example.jfiffiles.The current accept has limitations.
I need a way to tell dropzone to only accept
.jpgand.jpegbut none of the other JPG variantsI have the code above but I can still select JFIF possibly other JPG variants. How do I fix this ?
Just came here now after a too optimistic upgrade (didn’t read up on the breaking change introduced in v13), and wanted to leave my +1: This format is way too limited and/or verbose, depending on how you see it. Having the wildcard mime type from the key added to the
acceptattribute is not expected behavior.If your code works with all image formats, then you can use something like this:
The computed
acceptstring will be:image/*My code only works with
pngandjpegformats so to me it’s suitable a solution like:I could have also avoided to specify every single
jpegformat extension but I preferred that way just to stay safe.Here’s the issue with the “application/pdf” mime type. You can rename the image files to pdf extension and it accepts. Basically, it is not checking the Mime Type but simply extension.
having the same issue.
in the following
accept, no file type were accepted.setting
'*/text': ['.csv', '.xlsx'],enable both types, although.xlsxmime type isapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet.Thanks for the suggestion, however, your proposed change defeats the purpose of wildcard types? I don’t want to explicitly state all image extensions to get the same as
image/*.