Jquery File-Upload多部分发送单个文件选择

时间:2012-10-01 16:31:56

标签: jquery file-upload submit

以下代码试图强制定制一组要求,如下所述。我正在使用

Jquery File Upload widget here

我正在尝试将上传限制为文件集结构,并将此文件集作为单个Multipart HTTP上传发送到我们的服务器。我已设法通过绑定到'fileuploadchange'来强制执行此文件集,其中用户仅限于向上传队列添加某些文件类型(在这种情况下,他们一次只能上传1个TXT文件和1个WAV文件,不允许其他组合)。我的问题是使用绑定'fileuploadsubmit'来启动上传。如果用户在单个选择实例中同时选择TXT和WAV文件,则它可以正常工作,但是如果他们选择每个文件作为单个文件选择实例,则仅上载所选择的第二个文件。

.bind('fileuploadsubmit', function (e, data) {
        if($(".template-upload").length == 2){
            if(sent > 3){
                alert("Upload processing in progress. To upload another File-Set, please reset the form.");
                return false;
            }else if(sent == 3){
                sent++;
                return false;
            }else{
                if((data.files.length == 2)&&(sent == 0)){//Both files selected at once and work fine.
                    all_data = data;
                    sent = 2;
                }

                if(sent == 0){//get 1st file from single file selection and add to Global all_data variable for submission
                    all_data = data;
                    sent++;
                    return false;
                }else if(sent == 1){//get 2nd file from single file selection and add to Global all_data variable for submission
                    all_data['files'].push(data['files'][0]);
                    all_data['context'].push(data['context'][0]);
                    all_data['paramName'].push(data['paramName'][0]);
                    sent++;
                }

                if(sent == 2){//Only send when 2 files have been prepared in Global all_data variable
                    $("#loader_response").html("UPLOADING....");
                    sent++;
                    var jqXHR = all_data.submit();
                }
            }
        }else{
            alert("Only a file-set can be uploaded." + file_set_message);
            return false;
        }
    })

如果需要,可以提供任何帮助。

提前致谢。

编辑: 解决了以下问题:

              }else if(sent == 1){//get 2nd file from single file selection and add to Global all_data variable for submission
                data['files'].push(all_data['files'][0]);
                data['context'].push(all_data['context'][0]);
                data['paramName'].push(all_data['paramName'][0]);
                sent++;
              }

后跟data.submit()而不是all_data.submit()

进一步编辑: data.submit()更改导致JQuery“Too Much Recursion”错误。一起删除提交调用,因为当方法正确结束时将默认调用它。

0 个答案:

没有答案