I have several files being uploaded with fineuploader but there are 2 things I want to try to do.
I have this working if I add files after the first one is uploaded. I'm considering some sort of promise in the onsubmit callback that gets resolved after the first upload is complete. I'm just not sure how to pull that off.
Here is a bit of the code I currently have.
var first = true;
var returnedparam;
var uploader = new qq.FineUploader({
element: document.getElementById('fine-uploader'),
maxConnections: 1,
request: {
paramsInBody: false,
endpoint: '/endpoint1'
params: {
option:1
}
},
callbacks: {
onSubmit: function(id,name)
{
if(name.toLowerCase().indexOf('.jpg')>0 && !first)
{
//change the parameters for uploading the preview file.
if(returnedparam != '')
{
this._endpointStore.set('/endpoint2',id);
this.setParams({
option: returnedparam;
});
}
} elseif (!first) {
this._endpointStore.set('/endpoint3',id);
this.setParams({
option: returnedparam;
});
}
},
onComplete : function(id,name,obj,xhr)
{
if(first) //store a paramter from the first upload to be used for the remaining
{
returnedparam = obj.param;
first = false;
}
//do something with the file.
}
}
});
First off, onSubmit
will be fired for all files that have been "submitted" via the API or file chooser before any files are uploaded. So, that will not be useful to solve #2 in your question. Instead, you will need to handle the onComplete
event, grab any data from your server's response to the upload request. This will, ostensibly, contain the endpoint to use for subsequent files. There is a response
param passed to your onComplete
handler that will contain the parsed JSON response. At that point, you can call the setEndpoint
API method (leaving off the ID param) to update the endpoint for all subsequent files.
With auto-upload set to true (default) Fine Uploader will upload a file immediately after it is submitted, or at least queue it up until a connection is free. So, you'll need to consider handling files selection outside of Fine Uploader, sort though the files, then submit them in the proper order to Fine Uploader via the addFiles
API method. Currently, Fine Uploader does not sort the order of submitted files in any specific way (other than ensuring scaled images are uploaded before the original image).