精细上传器初始文件列表onStatusComplete null结果

时间:2017-05-15 19:08:27

标签: javascript fine-uploader

我想要找到in this SO Post找到的相同功能;

但是在onStatusChange回调中,对象为空。

callbacks: {
    onStatusChange: function(id, oldStatus, newStatus) {                            
        console.log('new status of ' + newStatus + ' for ID: ' + id);
        console.log(this.getItemByFileId(id));
    }

我得到以下输出

new status of upload successful for ID: 0

fine-uploader.min.js:2 [Fine Uploader 5.14.2] Caught exception in 'onStatusChange' callback - Cannot read property 'className' of null

我知道我服务器的会话响应没问题,b / c fine-uploader显示我的文件,文件名和删除按钮。

我试图支持的是什么?

这是我完整的上传代码供参考:

`
    var uploader_132963 = new qq.FineUploader({
        element: document.getElementById("uploader_132963"),
        session: { endpoint: 'https://localhost/session',  params : {  account: 'DEMO9', index: 1, psuuid: UUID_UPLOAD1},},
        template : 'qq-template1',
        debug: true,
        request : {
                endpoint: 'localhost',  
        },

        autoUpload: true,

        retry: {
                enableAuto: true
        },

        multiple: false,

        concurrent: {
                enabled: false
        },

        chunking: {
                concurrent: {
                        enabled : false,                    
                },

                enabled: true,
                mandatory: true,
                partSize: 2000000,
                success: {
                        endpoint: 'https://localhost/success'
                }
        },

        deleteFile: {
                enabled: true,
                endpoint: 'https://localhost',
                method: 'POST',

        },

        extraButtons: {
                folders: false
        },

        validation: {
                allowedExtensions: ['3g2','asf','avi','bmp','doc','docx','flv','gif','jpeg','jpg','m4a','m4v','mj2','mov','mp3','mp4','pdf','png','ppt','pptx','svg',],
                allowEmpty: false,
                itemLimit: 1,
                sizeLimit: 1024000000,
        },

                callbacks: {
                    onStatusChange: function(id, oldStatus, newStatus) {
                        if (newStatus == qq.status.UPLOAD_SUCCESSFUL) {
                            var fileItem = this.getItemByFileId(id); // will throw exception here
                        }
                    }
                }
})

`

2 个答案:

答案 0 :(得分:0)

通过初始文件列表加载文件时,将我的代码移动到onAllComplete回调可以得到所需的结果。在那个时间点,onStatusChange似乎没有this下的getItemByFileId函数。它会抛出一个例外     Caught exception in 'onStatusChange' callback - Cannot read property 'className' of null

答案 1 :(得分:0)

我遇到了与此处所述完全相同的问题。正如波弗洛里安所指出的那样。这是我处理从服务器正常上传的文件加载的两个固定文件的方式:

onAllComplete: function( arrSucceeded, arrFailed,) {

            if (arrSucceeded!==null && $.isArray(arrSucceeded)){

                for (var i=0,x=arrSucceeded.length;i<x;i++){

                //Get the template markup for the uploaded file
                var fileItem = this.getItemByFileId(arrSucceeded[i]);
                //Get the generated uuid. This is the same uuid that we save in the PHP SESSION. It points to the actual uploaded file
                var uuid = this.getUuid(arrSucceeded[i]);

            }
}
}

我正在使用版本5.16.2。雷,您在这个库中做得很棒。