React-dropzone: Allow multiple with a max count

Created on 28 Dec 2017  路  4Comments  路  Source: react-dropzone/react-dropzone

Is it possible to allow multiple files drop, but still limit it to a certain number? For example only allow at most 20 files to be dropped at a time.

Most helpful comment

onDrop={acceptedFiles => {
                    // do nothing if no files
                    let handleDropImages;
                    if (acceptedFiles.length === 0) {
                      return;
                    } else if(acceptedFiles.length > 5){ // here i am checking on the number of files
                      return notify('maxImages'); // here i am using react toaster to get some notifications. don't need to use it 
                    }else {
                      // do what ever you want 
                    }

                  }} 

All 4 comments

I'd think that was something to be handled by your onDrop function

@ktalebian I believe @moosch is correct you can overwrite the onDrop function to handle your use case.

Yes. Use onDrop callback.

onDrop={acceptedFiles => {
                    // do nothing if no files
                    let handleDropImages;
                    if (acceptedFiles.length === 0) {
                      return;
                    } else if(acceptedFiles.length > 5){ // here i am checking on the number of files
                      return notify('maxImages'); // here i am using react toaster to get some notifications. don't need to use it 
                    }else {
                      // do what ever you want 
                    }

                  }} 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

steverecio picture steverecio  路  4Comments

nzwnabdulwahid picture nzwnabdulwahid  路  4Comments

damon-kreft picture damon-kreft  路  3Comments

0xdevalias picture 0xdevalias  路  4Comments

emilpriver picture emilpriver  路  3Comments