Rectangle 27 0

javascript How to show a custom error message in DropzoneJS?


function showError($message)
    {
        http_response_code(415);
        die($message);
    }

Set the HTTP response code http_response_code(415); // Unsupported Media Type or http_response_code(415); // Not Acceptable

Note
Rectangle 27 0

javascript How to show a custom error message in DropzoneJS?


init: function() 
    {
        this.on("complete", function(file) {
            if (file.size > 3.5*1024*1024) {
                this.removeFile(file);
                alert('file too big');
                return false;
            }

            if(!file.type.match('image.*')) {
                this.removeFile(file);
                alert('Not an image')
                return false;
            }
        });
    },

Don't do complete: ... but instead:

Note
Rectangle 27 0

javascript How to show a custom error message in DropzoneJS?


complete: function(file) {
  if (file.size > 3.5*1024*1024) {
     alert("File was Larger than 3.5Mb!");
     return false;
  }

  if(!file.type.match('image.*')) {
    alert("Upload Image Only!");
    return false;
  }
}
success: function(file, response) {
  alert(response);
}

And to validate the file before uploading it use this:

If your server is returning response in JSON, you'll need to use JSON.parse before alerting it.

Just to add something I think is useful: you should listen to events (dropzonejs.com/#toc_8) not rewriting it (github.com/enyo/dropzone/issues/297). Cheers! :)

To get the response after the file was submitted to server use this in DropzoneJS:

Note