I am using http://fineuploader.com/ to upload a file. Works perfect. I then set params
in the request
object to send some additional parameters to be sent to the server. Works perfect. I then add another parameter to send using setParams
with the onSubmit callback. Doesn't work perfect as it deletes my original parameters. My desire is to add this last parameter to the original parameters, not replace them. My newPar is a dynamic valve, and not a constant as shown in my example.
Should I just not attempt to define parameters in the request
object and do it all in the callback?
Or set my added parameters in the request
object using an anonymous function?
Or maybe some other way?
var uploader = new qq.FineUploaderBasic({
button: document.getElementById('uploader'),
autoUpload: false,
multiple:false,
request: {
endpoint: 'uploads/handleUploads.php',
params: {id:123,task:'upload'}
},
callbacks: {
onSubmit: function(id, fileName) {
this.setParams({newPar:321});
}
},
debug: true
});
Your best bet would be to extend the default parameters ({ id: 123, task: 'upload' }
) in the onSubmit
with any new parameters. Here is an example:
// set your default parameters for all files via
// some object/function visible in fineuploader's scope
var defaultParams = {
id: 123,
task: 'upload'
}
var uploader = new qq.FineUploaderBasic({
multiple: false,
debug: true,
autoUpload: false,
button: document.getElementById('uploader'),
request: {
endpoint: "uploads/handleUploads.php",
},
callbacks: {
onSubmit: function (id, fileName) {
// Extend the default parameters for all files
// with the parameters for _this_ file.
// qq.extend is part of a myriad of Fine Uploader
// utility functions and cross-browser shims
// found in client/js/util.js in the source.
var newParams = {
newPar: 321
},
finalParams = defaultParams;
qq.extend(finalParams, newParams);
this.setParams(finalParams);
}
}
});
Fine Uploader has a ton of utility functions (docs/code), and I used one of them -- extend
-- to help create our final parameters object (assuming you are not using jQuery or any other dependencies).
Edit: Realized that you were not setting params for a specific file, but for all files, dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With