2016-07-30 83 views
-2

请给我代码示例来覆盖任何方法的uploadifive。如何重写uploadifive方法?

在这里我推出了我的js代码,请你看看。我想从后端检查重复的文件。我已经在控制器中的方法。

如果您提供任何样本以了解如何覆盖方法,那么我可以尝试前进。

$('#file_upload').uploadifive({ 
    'auto'    : true, 
    'buttonText'   : 'Select File', 
    'checkScript'   : false, 
    'queueSizeLimit'  : 10, 
    'fileSizeLimit'  : 10737418240, 
    'dnd'     : false, 
    'multi'    : true, 
    'removeCompleted'  : true, 
    'queueID'    : 'queue', 
    'simUploadLimit'  : 30, 
    'uploadLimit'   : 30, 
    'overrideEvents'  : ['onProgress'], 
    'uploadScript'  : '/files/pending', 
    // Triggered for each file that is added to the queue 
    'onAddQueueItem' : function(file) { 
    console.log(file.name + "file that is added to the queue"); 
    var folder = files.currentItemData(); 
    this.data('uploadifive').settings.formData = { 
          'timestamp'      : current_date_time(), 
          'authenticity_token'   : token(), 
          'attachment[folder_id]'   : folder.id, 
          'attachment[context_code]'  : current_context_code(), 
          'attachment[language]'   : uploadifive_language_code(), 
          'success_action_status'   : "201", 
         //'attachment[duplicate_handling]': file.duplicate_handling, 
                }; 
    }, 
    // Triggered when a file is cancelled or removed from the queue 
    'onCancel'   : function() {}, 
    // Triggered when the server is checked for an existing file 
    'onCheck'   : function() {}, 
    // Triggered during the clearQueue function 
    'onClearQueue'  : function() {}, 
    // Triggered when files are dropped into the file queue 
    'onDrop'   : function() {}, 
    // Triggered when an error occurs 
    'onError'   : function(file, fileType, data) {}, 
    // Triggered if the HTML5 File API is not supported by the browser 
    'onFallback'  : function() {}, 
    // Triggered when UploadiFive if initialized 
    'onInit'   : function() {}, 
    // Triggered once when an upload queue is done 
    'onQueueComplete' : function(file, data) {}, 
    // Triggered during each progress update of an upload 
    'onProgress' : function(file, e) { 
    if (e.lengthComputable) { 
     var percent = Math.round((e.loaded/e.total) * 100); 
    } 
    $('.uploadifive-queue-item').find('.fileinfo').html(' - ' + percent + '%'); 
    $('.uploadifive-queue-item').find('.progress-bar').css('width', percent + '%'); 
    }, 
    // Triggered once when files are selected from a dialog box 
    'onSelect'   : function(file) { 
    console.log(file.queued + ' files were added to the queue.'); 
    return; 
    }, 
    // Triggered when an upload queue is started 
    'onUpload'   : function(file) { 
    console.log(file + ' files will be uploaded.'); 
    file_select_done(); 
    }, 
    // Triggered when a file is successfully uploaded 
    'onUploadComplete' : function(file, data) { 
    res_data = JSON.parse(data); 
    $.ajaxJSON(res_data.success_url,'GET',{"authenticity_token" : authenticity_token},function(data) { 
     if (data && data["attachment"]){ 
     var file_id = data["attachment"]["id"]; 
     var file_name = data["attachment"]["display_name"]; 
     generate_li(file_name, file_id); 
     qutaUpdate(); 
     } 
    }); 
    console.log('The file ' + file.name + ' uploaded successfully.'); 
    }, 
    // Triggered for each file being uploaded 
    'onUploadFile'  : function(file) { 
    console.log('The file ' + file.name + ' is being uploaded.'); 
    } 
});}); 
+0

请给我们一个代码示例,说明你已经尝试了什么,以及失败了。 – Thomas

+0

>>现在你可以看到,我推出了我的js代码,请你看看。我想从后端检查重复的文件。我已经在控制器中的方法。 >>如果您提供任何样本以了解如何覆盖方法,那么我可以尝试前进。 – umishra

回答

0

,我发现我的上述问题的答案::)

$('#file_upload').uploadifive({ 
    'overrideEvents'  : ['onProgress','onCheck'], 
}); 

我在推杆阵列的方法uploadifive,现在我所有的代码中调用这里不uploadifive的代码。

谢谢!