For some quick background, uploadStoredFiles() is a method used in the FineUploader plugin to asynchronously send attached file data to a server path. I'm also using AngularJS for my application. My question is actually very similar to the one found here...
jQuery: wait for function to complete to continue processing?
... the big difference is that I don't have access to the callback function itself. Also, my script is running FineUploader as part of a larger form where attachments are optional, so using a FineUploader 'completed' callback won't help much either.
Here's a code sample. Basically, if there are no attachments then the page should reload. If there are attachments, they should be uploaded, and THEN the page should reload.
if(hasAttachments)
{
myuploader.uploadStoredFiles();
}
//AngularJS call to refresh page
$route.reload();
Most of the time, the page refreshes itself and the file is missing from its list until I do an additional refresh later on. I could hard code a wait time, but something about that seems inefficient and evil.
Any suggestions or solutions would be welcome. I would especially love an Angular-ish solution, but I'll take what I can get.
My attempt at summarizing my comments into a cohesive answer:
Fine Uploader has events that run code when certain things happen such as when a file is submitted to the uploader (
onSubmit
) or when a file has uploaded (onComplete
).The vanilla JavaScript would look something like,
You can use this Angluar example as a starting point for making a Fine Uploader directive.