3

I'm using dropzone version 5.2. I've been searching for days on stackoverflow and other places trying to figure out how to implement this but it seems most related posts are about renaming/appending filenames which I don't wish to do. I simply want to reject a filename longer than 30 characters. I have the proper server-side validation for filename length included in my php upload file already, but I want to do a client-side check as well. The reason is that I don't want a client spending time uploading a file with a long filename to only THEN get an error after the upload. I've tried many things, but I think I am getting closer with the following (still not working though):

            accept: function(file, done) {
                if (filename.val().length > 30) {
                    done("Filename needs to be 30 characters max!");
                }
                else { done(); }
            },

I'd appreciate any assistance to be pointed towards the right path on this.

EDIT: The solution turned out to be as listed in my own accepted answer

Well after day 5 of trying to figure this out, I finally realized it was the following:

            accept: function(file, done) {
                if (file.name.length > 30) {
                    done("Filename exceeds 30 characters!");
                }
                else { done(); }
            },

I hope this helps anyone else trying to figure it out

1

1 Answer 1

10

Well after day 5 of trying to figure this out, I finally realized it was the following:

            accept: function(file, done) {
                if (file.name.length > 30) {
                    done("Filename exceeds 30 characters!");
                }
                else { done(); }
            },

I hope this helps anyone else trying to figure it out

1
  • I wondered what was accept callback because it is not described in options page, but the github README says "src/options.js for all available options". Now, I understand. Thank you!. Jun 21, 2023 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.