Uploading Multiple Files to Google Drive with Google App Script

后端 未结 5 702
萌比男神i
萌比男神i 2020-11-27 17:57

I\'m trying to upload multiple files at once with my app. It recognizes when there are 2 or more files being selected. However, it will only upload the 1st file that is sele

5条回答
  •  渐次进展
    2020-11-27 18:05

    as @barragan's answer here is the best answer i found after hours and hours of searching for a question many people were asking, i've done a bit of development to improve the design a bit for others as a thanks. still a few bugs and chrome seems to run out of memory and give up with any file over 100MB

    here's a live version

    server.gs

    'function doGet() {
      return HtmlService.createHtmlOutputFromFile('form')
        .setSandboxMode(HtmlService.SandboxMode.IFRAME);
    }
    
    function uploadFileToDrive(base64Data, fileName) {
      try{
        var splitBase = base64Data.split(','),
            type = splitBase[0].split(';')[0].replace('data:','');
    
        var byteCharacters = Utilities.base64Decode(splitBase[1]);
        var ss = Utilities.newBlob(byteCharacters, type);
        ss.setName(fileName);
    
        var dropbox = "Something"; // Folder Name
        var folder, folders = DriveApp.getFoldersByName(dropbox);
    
        if (folders.hasNext()) {
          folder = folders.next();
        } else {
          folder = DriveApp.createFolder(dropbox);
        }
        var file = folder.createFile(ss);
    
        return file.getName();
      }catch(e){
        return 'Error: ' + e.toString();
      }
    }
    '
    

    form.html

    
        
        
        Focallocal Uploader
        
        
      






    i wasn't able to get the text fields to send an email with the details out, and ran out of time before working out how to hook them up to a Google Spreadsheet, so for the moment they don't record the information added

    as an added bonus, it looked fabulous with is in the form.html

          
    
    
    
    
        
        
        
    

    i took it out again as some of the scripts being called in were causing issues. if anyone can fix them it they add a lot to the appearance and functionality of the form

    *edit: i've been playing around with it and only around half of the files sent seem to arrive, so there are still some issues with both of the codes here atm

提交回复
热议问题