The jQuery fileupload docs say that I can send additional form data parameters by setting the formData
parameter to an object before submitting it. I'm doing that like this:
data.formData = {'a':'one', 'b':'two'};
...and then calling data.submit()
. My Java servlet (3.x) gets called, but when I try to retrieve the parameters in the normal way e.g.
request.getParameter("a");
...there's nothing there (i.e. it's null
). I've looked in request.getParameterNames()
and request.getParameterMap()
too, they're both empty.
How can I access the parameters?
These are my fileupload initialization options:
url: '/my-upload-servlet',
autoUpload: false,
singleFileUploads: false,
maxFileSize: 9000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|tif|tiff|pdf)$/i,
dataType: 'json',
previewMaxWidth: 128,
previewMaxHeight: 85,
disableImageResize: false,
previewCrop: true,
I've also tried setting the formData
option to an array of objects, which the docs say is also an option, e.g.
data.formData = [ {name:'a', value:'one'}, {name:'b', value:'two'} ]
...but it still doesn't work.
Here's the full code snippet for uploading the file (the commented out stuff are the other things that I've tried):
var params = new FormData();
params.append('params', JSON.stringify({a:'one', b:'two'}) );
data.formData = params;
//data.formData = {a:'one', b:'two'};
//data.formData = [
// { name: 'a', value: 'one' },
// { name: 'b', value: 'two' },
//];
//data.url = '/my-upload-servlet?a=one&b=two';
data.submit()
.success(function (result, textStatus, jqXHR) {
console.log('Hurray!');
}).error(function (jqXHR, textStatus, errorThrown) {
console.log('Boo!');
}).complete(function (result, textStatus, jqXHR) {
console.log('Done');
});
None of these are working for me.
No matter which of the above methods I try, calling HttpServletRequest.getParameter("a")
or HttpServletRequest.getParameter("params")
(in the case of the FormData) always returns null
.