question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] `accept` ignores extensions when used with wildcards

See original GitHub issue

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:

  1. Go to https://react-dropzone.js.org/#section-accepting-specific-file-types
  2. Scroll to the 2nd example in the Browser limitations section (the one that “works”).
  3. Drag a webp, jpg, gif, heic, heif file onto it
  4. 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 other-files

Desktop (please complete the following information):

  • OS: macOS 11.6.8
  • Browser: Brave v1.41.100
  • Version react-dropzone@14.2.2

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

5reactions
Haraldsoncommented, Nov 23, 2022

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 accept attribute is not expected behavior.

4reactions
akamfoadcommented, Aug 5, 2022

It would have been very helpful if the library accept a more generic data structure for accept, one I can think of is:

useDropzone({
    accept: [
        ".ext", "mime/type", { "mime/type": [ ".ext1, ".ext2"] }
    ]
})

This way, you can specify a specific extension without the need to specify the whole mimetype, for example when I want only .jpg and .jpeg files, I shouldn’t need to specify image/jpeg because this makes the input to accept every file extension that have the image/jpeg mimetype, for example .jfif files.

The current accept has limitations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid browser hang triggered by extensions bindly passing ...
Avoid browser hang triggered by extensions bindly passing URLs to `tabs.query` without escaping wildcards. Summary: Avoid browser hang triggered by extensions ...
Read more >
chrome.contentSettings API: Do not allow wildcard patterns ...
Description: chrome.contentSettings API: Do not allow wildcard patterns that match extension URLs. BUG=677714. Affected files (+60, -3 lines):
Read more >
CORS Access-Control-Allow-Headers wildcard being ignored?
I am having trouble getting a cross domain CORS request to work correctly using Chrome. Request Headers:
Read more >
include file completion ignores files without file extension - Bugs
So any files in /usr/include would be autocompleted since this directory should only contain headers anyway. Another alternative would be to allow patterns...
Read more >
How does the Windows RENAME command interpret wildcards?
Note - REN can be used to rename a folder, but wildcards are not allowed in either the ... then the file(s) will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found