0

My autoUpload set as false & I want to handle server error in frontend ( when I upload .gif or .mp3 ) using fileupload's error handler.

But the server response/textStatus always return success although my Php codes set accept_file_types as jpg|png.

Javascript codes :

$('#fileupload').fileupload({
    url              : 'sample/api/upload/',
    autoUpload       : false,
    maxChunkSize     : 50000, //5mb
    add: function (e, data) {
        var that = this;
        $.blueimp.fileupload.prototype.options.add.call(that, e, data);
        $("#submit_btn").off('click').on('click', function () {
            data.submit()
                .success(function (result, textStatus, jqXHR) { alert('success') })
                .error(function (jqXHR, textStatus, errorThrown) { alert('error') })
                .complete(function (result, textStatus, jqXHR) { alert('complete') });
        });
    }
});

  Php codes :

require('/UploadHandler.php');
$upload_handler = new UploadHandler(array(
    'upload_dir'        => 'sample/assets/uploads/tmp/',  
    'upload_url'        => 'http://localhost/sample/assets/uploads/
    'accept_file_types' => '/\.(jpe?g|png)$/i',
));

 

Ref :

Anyway to retrieve server fail response with autoUpload:false? Tq..

Community
  • 1
  • 1
Mavichow
  • 1,137
  • 16
  • 37
  • success is called when you get a response from the server so even though your server is responding with an error message, jQuery will interpret it as success, the error function is invoked when there is no response from server or there is error in sending the file. in your case file is being sent properly and something is getting returned so it will always be a success in the context of jQuery – adam Apr 22 '17 at 08:34
  • You need to return other than Http status code 200 to show the error callback. – Agam Banga Apr 22 '17 at 08:56

0 Answers0