Include params in the request body OR the query string

Updates since the original post/feature implementation

This is a new feature for 3.1.  I completed it sooner than originally scheduled due to the number of requests I received for this feature.  For backwards compatibility reasons, all parameters will be specified in the query string by default, but you can override this by setting the paramsInBody property (inside the request option).  If this option is set, all parameters will be sent in the request body only.  Note that this will all force all requests to be multipart encoded, so you will need to account for this in your server code appropriately.

Please note that all parameters, whether they are included in the query string or in the request body (no longer applies to request body params as of 3.3), are URI component encoded.  This means that you must decode the parameter keys and values server-side.  Javascript’s encodeURIComponent function, which is used to encode the parameters client-side, uses the UTF-8 encoding scheme.  So, you must ensure the same encoding is used server-side.  Also, be sure to set the charset meta tag in your HTML.

Fine Uploader params are powerful

The request params option of Fine Uploader is actually quite powerful.  It may be useful for you to understand its full potential.

Simple key-values

The most basic and common parameters sent along with each upload request will be simple key-value pairs: the key being a string and the value a number or string.  For example:

var uploader = new qq.FineUploader({
    request: {
        endpoint: 'upload/handler',
        params: {
            one: 1,
            two: 'two',
            'three': 'three'
        }
    }
});

The parameters will be passed either in the query string, or the body of the request (depending on the value of the paramsInBody option).  In this case, 3 parameters will be passed, with keys of “one”, “two”, and “three”, along with values of “1”, “two” and “three” respectively.

Nested objects

You may also pass objects as values.  For example:
var uploader = new qq.FineUploader({
    request: {
        endpoint: 'upload/handler',
        params: {
            foo: {
                one: 'bar',
                two: 'bar2'
            }
        }
    }
});
Fine Uploader ensures the context of each parameter is kept intact.  So, sever-side, you will see a key of “foo[one]” with a value of “bar” and a key of “foo[two]” with a value of “bar2”.  Fine Uploader supports multiple levels of object nesting.

Functions as values

Finally, you may include functions as parameter values.  Take the following:
var fileNum = 0,
    uploader = new qq.FineUploader({
        request: {
            endpoint: 'upload/handler',
            params: {
                fileNum: function() {
                    return fileNum++;
                }
            }
        }
    });
Note that this function will be evaluated for each file that is submitted.  So, along with the first file request, a parameter of “fileNum” will include a value of “0”.  The next file will have the same param, this time with a value of “1”.  Please understand that any params with a function value must return either a number or a string, and not an object.
As always, if you have any requests to improve this feature, or any feedback at all, feel free to let me know.
-Ray Nicholus