代码之家  ›  专栏  ›  技术社区  ›  user2381742

完成多个文件上传

  •  9
  • user2381742  · 技术社区  · 11 年前

    我有一个关于Blueimp jQuery文件上传插件使用的问题( https://github.com/blueimp/jQuery-File-Upload )

    有一个回调函数或替代方法,可以知道何时完成多个文件的上传? 我不想知道每个文件的上传什么时候完成,但整个过程什么时候完成(所有上传都符合要求)。

    还有机会了解实际加载了多少文件以及请求了多少文件?

    4 回复  |  直到 11 年前
        1
  •  9
  •   coder    9 年前

    请看一下 "stop" callback 选项:

    .bind('fileuploadstop', function (e) {/* ... */})

    如果你想跟踪上传的文件,试着使用这个:

    $('#fileupload').bind('fileuploaddone', function (e, data) { }
    

    Your collections 数据文件 only contain 1 object each, hence you can track the count of files been uploaded.

        2
  •  5
  •   BoCyrill    8 年前

    是的,您可以将其称为API来跟踪多次上传过程的结束:

    var $fileInput = $('#fileupload');
    
    $fileInput.on('fileuploaddone', function(e, data) {
        var activeUploads = $fileInput.fileupload('active');
        /*
         * activeUploads starts from the max number of files you are uploading to 1 when the last file has been uploaded.
         * All you have to do is doing a test on it value.
         */
        if(activeUploads == 1) {
            console.info("All uploads done");
            // Your stuff here
        }
    }
    
        3
  •  1
  •   shane lee    10 年前

    就在这些家伙身上,你可以使用以下方法获取活动上传的数量:

    var activeUploads = $('#fileuploadForm').fileupload('active');
    

    请参阅: https://github.com/blueimp/jQuery-File-Upload/wiki/API#retrieving-the-number-of-active-uploads

    我打算在总是回调函数上使用一个计数器来与这个变量进行比较。 但stop看起来效果很好。

    只是想澄清一下。如果我有多个单一的文件上传请求是停止(),最好的方法是什么?

        4
  •  0
  •   Marcelo Agimóvel    5 年前

    在我的案例中,我遵循了两个答案,但没有成功。

    所以禁用iPV6可以让事情正常运行。iPV6似乎对所有上传都投了假阳性。