Krajee file-input widget 'upload' method throws exception

后端 未结 3 885
醉酒成梦
醉酒成梦 2021-01-25 14:43

I am using fileinput widget form krajee: http://plugins.krajee.com/file-input

What I am doing wrong using \'upload\' method ? When I upload files by pressing upload but

3条回答
  •  一整个雨季
    2021-01-25 14:54

    I was having the same issue, but I couldn't find a good solution, so I came up with a workaround.

    I'm using the 'filebatchuploadcomplete' event, so I know when all the files in the batch are uploaded succesfully (even if there's only one file in the batch to be uploaded). When this event is triggered, I call 3 methods of the fileinput inside the closure function to clear, reset and re-enable the fileinput area (dropzone too, if you're using one).

    THIS METHOD WORKS REGARDLESS IF THE ABOVE MENTIONED ERROR IS THROWN OR NOT BY THE PLUGIN.

    Here's my sample:

    $('#myFileuploadArea').fileinput({
    
        //set the upload options here
        ...
        ...
        ...
    
    }).on("filebatchselected", function(event) {
    
        // trigger upload method immediately after files are selected
        $('#myFileuploadArea').fileinput("upload");
    
    }).on('filebatchuploadcomplete', function(event) {
    
        // this part is triggered when all files are succefully 
        // uploaded from the batch, even if there was only one file selected
        console.log('ALL FILES IN BATCH UPLOADED SUCCESSFULLY');
        $('#myFileuploadArea').fileinput('refresh');
        $('#myFileuploadArea').fileinput('reset');
        $('#myFileuploadArea').fileinput('enable');
    
    });
    

提交回复
热议问题