Blueimp jQuery File Upload plugin - “Empty file upload” result PHP

后端 未结 6 902
暖寄归人
暖寄归人 2021-01-04 22:59

Here\'s the plugin: https://github.com/blueimp/jQuery-File-Upload

I\'m having a problem getting the response I want from the plugin after uploading a file.

O

6条回答
  •  庸人自扰
    2021-01-04 23:36

    The "Empty file upload result" will occur when adding HTML (and in programmatical result DOM) objects to the template that are outside of the HTML tag, e.g.: let's say you add another to the template

    This will result in the file(s) being uploaded correctly and for every uploaded file you will get the "Empty file upload result" once.

    Seems to have to do something with the JS template engine.

    This can be fixed in jquery.fileupload-ui,js, right after line 128

    Original code:

        // Callback for successful uploads:
    done: function (e, data) {
        var that = $(this).data('blueimp-fileupload') ||
                $(this).data('fileupload'),
            files = that._getFilesFromResponse(data),
            template,
            deferred;
        if (data.context) {
            data.context.each(function (index) { // LINE 128
                var file = files[index] ||
                        {error: 'Empty file upload result'},
                    deferred = that._addFinishedDeferreds();
    

    Add the following code after line 128:

    if (!$(data.context[index]).hasClass(that.options.uploadTemplateId)) { return true; }
    

    Resulting code:

        // Callback for successful uploads:
    done: function (e, data) {
        var that = $(this).data('blueimp-fileupload') ||
                $(this).data('fileupload'),
            files = that._getFilesFromResponse(data),
            template,
            deferred;
        if (data.context) {
            data.context.each(function (index) { //LINE 128
                if (!$(data.context[index]).hasClass(that.options.uploadTemplateId)) { return true; } // YOUR ADDED LINE
                var file = files[index] ||
                        {error: 'Empty file upload result'},
                    deferred = that._addFinishedDeferreds();
    

    Hope this helps others :)

提交回复
热议问题