javaScript upload multiple files - when it has finished -


i have javascript function upload files , want know when files uploaded, when upload of multiple files has finished. there possibility this?

function uploadfiles(files, userid, projectid, successcallback, progresscallback) {         if (files && files.length) {             (var = 0; < files.length; i++) {               var file = files[i];               if (!file.$error) {                 upload.upload({                     url: 'api/fileuploads/fileupload/' + userid + '/' + projectid,                     data: {                       file: file                       }                 }).then(function (resp) {                     if (successcallback) {                         successcallback(resp);                     }                 }, null, function (evt) {                     var progresspercentage = parseint(100.0 * evt.loaded / evt.total);                     var log = 'progress: ' + progresspercentage + '% ' + evt.config.data.file.name + '\n';                     if (progresscallback) {                         progresscallback(log);                     }                 });               }             }         }     }; 

you can try add counter count how many times upload promise have resolved:

function uploadfiles(files, userid, projectid, successcallback, progresscallback) {         if (files && files.length) {             var count = 0;             (var = 0; < files.length; i++) {               var file = files[i];               if (!file.$error) {                 upload.upload({                     url: 'api/fileuploads/fileupload/' + userid + '/' + projectid,                     data: {                       file: file                       }                 }).then(function (resp) {                     if (++count == files.length) {                         if (successcallback) {                             successcallback(resp);                         }                     }                 }, null, function (evt) {                     var progresspercentage = parseint(100.0 * evt.loaded / evt.total);                     var log = 'progress: ' + progresspercentage + '% ' + evt.config.data.file.name + '\n';                     if (progresscallback) {                         progresscallback(log);                     }                 });               }             }         }     }; 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -