【问题标题】:Fineuploader cancel upload after user response on file submitFineuploader 在用户响应文件提交后取消上传
【发布时间】:2013-07-16 05:11:15
【问题描述】:

我正在尝试让用户响应文件提交以取消或不取消文件上传,但它似乎没有停止文件上传可能是我遗漏了一些建议

onSubmit: function(id, name) {
                    doc_status = $('#doc_attach_status').val(); 
                                if (doc_status == "true" ) {

                         if(confirm("Please note, if you upload a new PDF, old one will be replaced") == false){

                              manualuploader.cancelAll(); // tried but does not work    
                             cancelAll();// tried but does not work 
                             cancel(id);// tried but does not work 
                             $(this).cancelAll();// tried but does not work 
                             }

                    }

               },   

是的,我能够成功上传文件......

这是我正在使用的完整功能...

var manualuploader = new qq.FineUploader({
            callbacks : {
                onComplete : function(id, name, response) {
                }
            },
            element : $('#pdf-fine-uploader')[0],
            request : {

                endpoint : "/UploadPdf",
                params : {
                    variant_id : $('#variant_id').val(),
                }
            },
            multiple : false,
            autoUpload : true,
            text : {
                uploadButton : '<i class="icon-plus icon-white"></i> Select File </br> Maximum upload size less than 2 MB'
            },
            validation : {
                allowedExtensions : ['pdf', 'txt'],
                //sizeLimit: 51200, // 50 kB = 50 * 1024 bytes
                sizeLimit : 2097152//, // 2 MB = 2 * 1024 * 1024 bytes
                //itemLimit : 6
            },
            callbacks : {

                onSubmit: function(id, name) {
                    doc_status = $('#doc_attach_status').val(); 
                    // var answer = confirm("Please note, if you upload a new PDF, your current Tasting Notes PDF will be replaced");   
                    if (doc_status == "true" ) {

                         if(confirm("Please note, if you upload a new PDF, your current Tasting Notes PDF will be replaced") == false){

                              manualuploader.cancelAll();    

                             }

                    }

               },                   
                onComplete : function(id, fileName, responseJSON) {
                    if (responseJSON.success) {
                        $('.doc_link').html(responseJSON.docurl);
                        $('#doc_delete_link').addClass('icon-remove-sign');
                         $('.doc_description_head').show();
                         $('#doc_pdf_head').show();
                         $('.doc_description_div').show();
                         $('.description_save').show();
                          $('#doc_delete_link').show();
                    }
                }

            }

        });
        $('#triggerUpload').click(function() {
            manualuploader.uploadStoredFiles();
        });

    });

【问题讨论】:

  • 如文档所述,您可以在 onSubmit 回调中返回 false 以要求 Fine Uploader 忽略相关文件。

标签: javascript jquery ruby-on-rails-3 fine-uploader


【解决方案1】:

终于得到了非常简单的解决方案……

只需使用

在得到用户响应后返回 true 或 false ....

onSubmit: function(id, name) {
                doc_status = $('#doc_attach_status').val(); 
                            if (doc_status == "true" ) {

                     if(confirm("Please note, if you upload a new PDF, old one will be replaced") == false){

                         retutn false;
                         }

                }

           },   

【讨论】:

    猜你喜欢
    • 2013-05-17
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多