Fineuploader在用户响应文件提交后取消上传

时间:2013-07-16 05:11:15

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

我试图在文件提交时获取用户响应取消或不取消文件上传但似乎没有停止文件上传可能是我遗漏了某些建议

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();
        });

    });

1 个答案:

答案 0 :(得分: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;
                         }

                }

           },