Topic: How to use one plupload (core) instance with multiple browse buttons?
I have two buttons, each are supposed to show the browse dialog for a single file and each button has its own data-options that will be passed as multipart_params:
<button id="browse_one" data-uptype="one" data-dbid="42">Upload file</button>
<button id="browse_two" data-uptype="two" data-dbid="42">Upload file</button>
The 'uptype' and 'dbid' values are passed as multipart_params to the php uploadhandler so it can update the correct value in the database and tell where to save the file to. This already works fine with just a single browse button.
Now I want to have the second button also open the file dialog, and of course pass its own 'uptype' and 'dbid' values.
(I know I could init two or more plupload instances on a page, but that would also mean multiple uploadhandlers, and more for each other upload button elsewhere. I'd like to just use the single plupload instance and uploadhandler, and have each button pass their multipart_params.)
I've found this topic (which links to this one) and both seems to be what I'm trying to do. But the example/advice there does not tell me where to actually put it in the code, but I think it should be in the click event of 2nd button? I've tried to boil it down to just showing an alert if it can actually trigger the browsedialog but nothing I've tried so far works. How do I do this? Where do I add the code to trigger the browsebutton click, but with its own data for the multipart_params?
My js file with the plupload stuff looks like this:
$('#browse_one').click(function(event) {
event.preventDefault();
});
$('#browse_two').click(function(event) {
//from what I understand, I should be able to trigger "click" of button one,
//and hopefully pass the data of button two here...?
if (uploader.features.triggerDialog) {
alert ( 'We can trigger the file dialog programmatically!' ); //this does not show up at all...
}
event.preventDefault(); // cancel default behavior
});
initPlUpload();
function initPlUpload() {
var uptype = $('#browse_one').data("uptype"); //gets the two values for multipart_params...
var dbid = $('#browse_one').data("dbid"); //...from button one
var uploader = new plupload.Uploader({
runtimes : 'html5',
browse_button : 'browse_one', //this of course works for the first button...
//...etc...all the settings and the rest of plupload here...
I really wish there was a way to open the file dialog with a plupload command, and passing the data-variables. Instead of triggering the original plupload browsebutton set in its options, feels like an incorrect way of doing things tbh.