1

I have list of URL links on my google app script html page. I have a download button. When I click the download button, I want to download all files from my google drive to my computer using the URL links.

To start with: I tried for one link to put it in a folder on my google drive. But it doesn't work.

I have shared the spreadsheet file in public domain here https://docs.google.com/spreadsheets/d/1sXWWAdfEIJSj9_QPBjkR6CKhd4bzrYIMa4hImipySWI/edit?usp=sharing

The web link: https://script.google.com/macros/s/AKfycbwkBfuZzSDV5UgQLugJoWXH-2pDrtqsd2Ph5HAkx_oFOvR6gD0/exec please search for a name "sam"

Would you help me please?

Thank you.

// Start html part

<!DOCTYPE html>
<html>
 <head>
    <base target="_top">
 </head>
<body>
<p>Enter the name: sam </p>

<div>
<form id="searchform">
      <input name="nameperson" type="text">
      <input type="submit" value="search">
</form>
 </div>
 <div id="result">
 </div>

 <div id="download" hidden="true"> 
    <button> download </button>
 </div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<script>
  $(document).ready(function() {
  $("#searchform").submit(function(){

      google.script.run.withSuccessHandler(function(valreturn){
          var response=JSON.parse(valreturn);
          var newHTML=[];
          newHTML.push('<table>' + '<tr>' +'<th>'+"Name"+'</th>'+
                                            '<th>'+"URL"+'</th>'+ '<tr>');

          for( var i=response.length-1; i >= 0 ; i--){
               newHTML.push('<tr>' + '<td>' + response[i].name + '</td>' +
                                        '<td>' + '<a href= " ' + response[i].url + ' " target="_blank" >' + "url" + '</a>' + '</td>' + '</tr>');

          }
          $("#result").html(newHTML.join(""));
          $("#download").show();
      }).seachRecord(this);
  });


  $("#download").click(function() { 

    alert("how can I download these files ?");
  });


  });

 function preventFormSubmit() {
        var forms = document.querySelectorAll('form');
        for (var i = 0; i < forms.length; i++) {
          forms[i].addEventListener('submit', function(event) {
            event.preventDefault();
          });
        }
      }


 window.addEventListener('load', preventFormSubmit);
</script>

  </body>
</html>

//end html

  function getFilepdf() { 
             var fileURL="https://drive.google.com/file/d/0BybO_Qe9EIRKZExPSWJJXzl1ajQ/view"; 
             var response = UrlFetchApp.fetch(fileURL);  
             var fileBlob = response.getBlob(); 
              fileuploadpdf(fileBlob);  
              }


    function fileuploadpdf(filedata){
        try {
        var dropbox = "stackflowfolder";
        var folder, folders = DriveApp.getFoldersByName(dropbox);
        if (folders.hasNext()) {
          folder = folders.next();
        } else {
          folder = DriveApp.createFolder(dropbox);
        }
        var blob = filedata; 
        var file = folder.createFile(blob);    

           } catch (error) {

        return error.toString();   } 
  }
Jona
  • 396
  • 1
  • 7
  • 22
  • I don't quite understand your question? You want to download the entire contents of your Google Drive from the click on your HTML page?? – James D Jun 22 '17 at 10:20
  • I have a search function to select specific URL . I already did the search function. I want to download the files based on the URL form the Google drive. @ James – Jona Jun 22 '17 at 13:21
  • Add the Google Apps Script HTML page. See [mcve]. – Rubén Jun 23 '17 at 01:11
  • I have shared the spreadsheet file here. Thank you in advance for you help.https://docs.google.com/spreadsheets/d/1sXWWAdfEIJSj9_QPBjkR6CKhd4bzrYIMa4hImipySWI/edit?usp=sharing @Ruben – Jona Jun 23 '17 at 07:29
  • @user7428112: That's fine but by "Add the Google Apps Script HML page" I meant to "add the code" of that page. – Rubén Jun 23 '17 at 13:56
  • I think [downloadAsFile(filename)](https://developers.google.com/apps-script/reference/content/text-output#downloadasfilefilename) will be of use to you here. For the code demo, check this [SO post](https://stackoverflow.com/questions/20281272/initiate-a-download-from-google-apps-script) as it may provide insights to your usecase. – ReyAnthonyRenacia Jun 23 '17 at 15:15
  • Still, I couldn't figure out. Anyone who can help me? – Jona Jun 26 '17 at 09:23

0 Answers0