Search code examples
jqueryasp.netjquery-file-uploadhttpcontextblueimp

Sending additional parameters with blueimp fileupload


I'm using blueimp file-upload's capability to send additional parameters back to the server that are set inside add:

var simpleImport = false, replaceImport = false, mergeImport = false;   
$uploadButton.fileupload({
            url: myURL,
            formData: { simple : simpleImport, replace : replaceImport, merge : mergeImport }, 
            add: function (e, data) {
                var valid = true;
                // validation logic
                if (valid) {
                    if (condition №1) simpleImport = true;
                    else if (condition №2) replaceImport = true;
                    else if (condition №3) mergeImport = true;
                    data.submit();
                }
            },
            done: function (e, data) {
                if (data.result) {
                    oTable.ajax.reload();
                }
            },
            fail: function (e, data) {
                alert("shit happens");
            }
        });

On the server I read them in a such way:

var merge = Convert.ToBoolean(Context.HttpContext.Request.Form["merge"]);
var simple = Convert.ToBoolean(Context.HttpContext.Request.Form["simple"]);
var replace = Convert.ToBoolean(Context.HttpContext.Request.Form["replace"]);

But despite changing its values inside add I still got all of them equal to false in my handler. Is there any method to obtain proper values except using hidden inputs or I'm doing something entirely wrong?


Solution

  • Ok. I finally solve this issue: instead of adding additional parameters in settings object:

    $uploadButton.fileupload({
          url: myUrl,    
          formData: { additional params },
          ....
    });
    

    they should be specidied directly before submitting the data in add method:

    add: function (e, data) {
        .....
        data.formData = { additional params };
        data.submit();
    },