Multiple upload files new function
Does this script still work? I found it in an old thread?
I'm assuming the data source would be something like:
LoginDB__files_upload_service // a service which uploads files to the files collection
and the file list would be at least 1 file such as:
image_base64_1 // A picture from the camera
or an array of file names taken with the camera?
I have saved 6 pictures from my camera into local storage and would like to upload all 6 to the files database. They are stored in Local Storage:
image_base64_1 
 image_base64_2 
 image_base64_3 
 image_base64_4 
 image_base64_5 
 image_base64_6
// Here's the function I'm talking about
function uploadMultipleFilesHelperNew(datasource, fileList) { 
     var isCorrectService = false; 
     if (datasource) { 
         if (datasource.service && datasource.service.requestOptions) { 
             var options = datasource.service.requestOptions; 
             isCorrectService = options.type === 'post' && options.contentType === false && /^.*\/files$/i.test(options.url); 
         } 
     } 
     if (isCorrectService) { 
         if (fileList) { 
             var data = new FormData(); 
             for (var i = 0; i < fileList.length; i++) { 
                 appendItem(data, fileList); 
             } 
             try { 
                 datasource.execute({ 
                     'allowDataModification': false, 
                     'processData': false, 
                     'body': {data: data}, 
                     'cache': false 
                 }); 
             } catch (exception) { 
                 console.log(exception.name + ' ' + exception.message); 
                 hideSpinner(); 
             } 
         } 
     } else { 
         console.warn('This data source not be supported in the method of upload multiple files'); 
     } 
     function appendItem(formData, item) { 
         if (item) { 
             if (item.type === 'file') { 
                 item = item.files; 
             } 
             if (item instanceof FileList) { 
                 for (var i = 0; i < item.length; i++) { 
                     appendItem(formData, item); 
                 } 
                 return; 
             } 
             var name; 
             if (item.name) { 
                 name = item.name; 
             } 
             formData.append(name, item); 
         } 
     } 
 }