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.

pass rejection reason to onDropRejected callback

See original GitHub issue

Do you want to request a feature or report a bug?

  • I found a bug
  • I want to propose a feature

I’d like to get a reason for rejection in the onDropRejected callback currently I only get the file that was rejected. There was a request opened up previously #735, but it was closed. I am not sure why because the request was valid one and the response didn’t really help the reporter.

From what I can see there can be 3 reasons:

  • you dragged multiple files to multiple={false} dropzone
  • bad mime type
  • file too big

Sure I can have a series of if statements in my callback to recognize what was the reason for rejection, but why do this work again when react-dropzone already done it?

Also it would be nice to have default error messages for those 3 scenarios, I’d propose:

  • File ${file.name} is not supported
  • Only accepts a single file
  • File ${file.name} is ${bytes(file.size)}, the upper limit for file size is ${bytes(maxFileSize)}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
DominikSerafincommented, Mar 24, 2019

Thanks for looking into it @rolandjitsu

Any implementation for this will be step forward in my opinion - but I have one suggestion - maybe it would be better to keep the error/validation as a string code that can be easily compared by a developer if he wants to show their own error messages?

I mean something like I’ve previously suggested: file-invalid-type, file-too-large, file-too-small, file-overflow/file-excessive, etc.

Or maybe even combined approach? Like this:

interface FileError extends Error {
  message: string; // e.g. 'File is larger than {maxSize}', 'File type does not meet {accept} criteria', etc.
  code: string; // e.g.  'file-too-large' 
  file: File;
}
8reactions
omcg33commented, Sep 27, 2019

HEllo. Any news about PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dropzone - Procore
onDropRejected, function, false. Callback for when the drop event occurs. Note that if no files are rejected, this callback is not invoked.
Read more >
react-dropzone
Note that the onDrop callback will always be invoked regardless if the dropped files were accepted or rejected. If you'd like to react...
Read more >
react-dropzone - accessing files added by click not drop
The above code handles both drag and drop, however it only gives you the latest added files and not the entire list of...
Read more >
10 React-Dropzone Best Practices - CLIMB
To add validation logic to React-Dropzone, you can use the onDropAccepted and onDropRejected props. These props allow you to specify a callback ......
Read more >
5 reasons why you get reject from Thailand Pass - YouTube
5 reasons why you get reject from Thailand Pass... Appreciated in my information and want to buy me a coffee (Donate...
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