Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DropZone.js server side validation

I'm doing server side validation for the files uploaded. Not every file that makes it to the server is stored. How can I display/trigger the error on the file(s) that were not successfully stored on the server. I've tried adding a server Validation function but can't figure out how to do it... Please help

                  this.on("successmultiple", function (file, successResponse) {
                        uploadResult = eval(successResponse);
                        toastr.options.positionClass = "toast-bottom-right";
                        var ErrorMessage = "";
                        for (var i = 0; i < uploadResult.ResultList.length; i++) {
                            var result = uploadResult.ResultList[i];
                            if (result.IsSuccessful === "True") {
                                toastr.success(result.Message);
                                if (hdnFileIDList !== "")
                                    hdnFileIDList = hdnFileIDList + "|" + result.ID;
                                else
                                    hdnFileIDList = result.ID
                            }
                            else {
                                //-- trigger dropzone error
                                toastr.warning(result.Message);
                                //this.ValidationError(file, result.Message);
                                file.accepted = false;
                                file.status = Dropzone.ERROR;
                                dropzone.serverError(file, result.Message);
                                //dropzone.emit("errormultiple", file, result.Message);
                            }                                
                        }
                        $("#<%=hdnSharedFileObjNewFileIDList.clientID%>").val(hdnFileIDList);
                    });
like image 932
youngaj Avatar asked Mar 24 '26 14:03

youngaj


1 Answers

Solved my problem by adding the following code to Dropzone.js then calling it from my "successmultiple" event when I see and error in my returned JSON from the server.

 Dropzone.prototype.serverError = function (file, message) {
                file.accepted = false;
                file.status = Dropzone.ERROR;
                return this._errorProcessing(file, message);
            };
like image 153
youngaj Avatar answered Mar 27 '26 02:03

youngaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!