0

i just want to upload file from my external html(localhost) then upload to Google Drive, or how can i get the link of last uploaded file to my php or html. Sorry for my bad english i hope you understand my problem, but its big problem for our project. Any feedback will make a big help for us. Thank you!

This is my code from Code.gs

  var html = HtmlService.createHtmlOutputFromFile('index');
  return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

function uploadFiles(data)
{
  var file = data.myFiles;
  var myfolder = checkFolder();
  var folder = DriveApp.getFolderById(myfolder);
  var createFile = folder.createFile(file);
  return createFile.getUrl();
}



function checkFolder()
{
var folder = DriveApp.searchFolders("title contains 'QCU LMS'");
if(folder.hasNext()){
  var folderId = folder.next().getId();
   Logger.log(folderId);
    return folderId;
}else{
  Logger.log("No QCU LMS Folder Found.");
  var folders = DriveApp.createFolder("QCU LMS");
  folders.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
  return folders.getId();
}
} 

This is my code from index.html

<html>
 <head>
   <base target="_top">
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>

 .buttonload {
 background-color: #4CAF50; /* Green background */
 border: none; /* Remove borders */
 color: white; /* White text */
 padding: 12px 24px; /* Some padding */
 font-size: 16px; /* Set a font-size */
}

/* Add a right margin to each icon */
.fa {
 margin-left: -12px;
 margin-right: 8px;
}
</style>
 </head>
 <body>

   <h1>Upload Files</h1>
       <form>

    <input type="file" id="myFiles" name="myFiles" required>
    <br>
    </br>
       <input type="button" id="submitBtn" value="Upload Files" class="buttonload">
        <a href="https://www.facebook.com/" id="resp" target="_blank"></a>
 <div id="mySrc">
       <input type="text" id="resps">
      </div>
<div id="myDIV">
       <button class="buttonload">
 <i class="fa fa-circle-o-notch fa-spin"></i>Uploading...
</button>
</div>

       </form>



   <script>
var x = document.getElementById("myDIV");
var y = document.getElementById("submitBtn");
 x.style.display = "none";
     document.getElementById('submitBtn').addEventListener('click', 
     function(e){
     google.script.run.withSuccessHandler(onSuccess).uploadFiles(this.parentNode);
     x.style.display = "block";
     y.style.display = "none";
     })
     
     function onSuccess(data){
     document.getElementById('resp').href = data;
     document.getElementById('resps').value = data;
 document.getElementById('resp').innerHTML = "Uploaded Check Here";
 x.style.display = "none";
     y.style.display = "inline-block";
     }
     </script>
 </body>
</html>
  • 1
    I think that when you use V8 runtime at the script editor, this thread might be the answer for your question. https://stackoverflow.com/q/60742695 But I cannot understand about `how can i get the link of last uploaded file to my php or html.`. I apologize for this. Can I ask you about the detail of your goal? – Tanaike Feb 25 '21 at 23:52
  • we try to get the link from `return createFile.getUrl(); ` to our local html, like when the google apps script link then input to iframe in our html, then we want to get the new uploaded file link – cadburry gaming Feb 28 '21 at 14:35
  • Thank you for replying. I'm glad your issue was resolved. – Tanaike Mar 01 '21 at 01:10
  • So you basically want to upload a file to Drive with an Apps Script web app and then get the URL link of this new file to display it in your web app? – Mateo Randwolf Mar 01 '21 at 10:01
  • @MateoRandwolf yes sir exactly – cadburry gaming Mar 01 '21 at 14:20
  • Who should have access to your web app? Anyone, only yourself, anyone in your organization? – Mateo Randwolf Mar 02 '21 at 16:04
  • @MateoRandwolf we set it to in our organization sir – cadburry gaming Jun 16 '21 at 12:16

0 Answers0