retesere20

Untitled

Jan 2nd, 2017
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function doGet(e) {
  3. //return HtmlService.createHtmlOutputFromFile('form.html');
  4. return HtmlService.createHtmlOutput('<!--Web: ctrlq.org; Twitter: @labnol; Email: amit@labnol.org; -->' +
  5. '<form id="myForm"><input type="file" name="myFile"><input type="submit" value="Upload File" onclick="this.value=\'Uploading..\'; google.script.run.withSuccessHandler(fileUploaded) .uploadFiles(this.parentNode); return false;"></form>' +
  6. '<div id="output"></div> <script> function fileUploaded(status) { document.getElementById("myForm").style.display = "none"; console.log(status); document.getElementById("output").innerHTML = status; }</script>'+
  7. '<style> input { display:block; margin: 20px; }</style>');
  8. }
  9.  
  10.  
  11. function uploadFiles(form) {
  12. try {
  13. var targetFold = "uploads";
  14. var folder, folders = DriveApp.getFoldersByName(targetFold);
  15.  
  16. if (folders.hasNext()) { folder = folders.next(); }
  17. else { folder = DriveApp.createFolder(targetFold ); }
  18. var fileBlob = form.myFile;
  19. var Upldfile = DriveApp.getFilesByName(form.myFile);
  20. if (Upldfile.hasNext() !== true) {
  21. var file = folder.createFile(form.myFile);
  22. return file.getName() +"| uploaded successfully: " + file.getUrl();
  23. }
  24. else { return "file already exists"; }
  25. } catch (error) {
  26. return error.toString();
  27. }
  28.  
  29. }
RAW Paste Data