Forked from erajanraja24/Upload files from Blog or Website to Google Drive
Created
October 9, 2020 01:35
-
-
Save OTsector/2990d0d8ee116d9797c7f34ee51d6db8 to your computer and use it in GitHub Desktop.
Upload files from Blog/Website to Google Drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Google Apps Script. Need to be pasted on the code.gs file | |
function doGet() { | |
var html = HtmlService.createHtmlOutputFromFile('index'); | |
return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); | |
} | |
function uploadFiles(data) | |
{ | |
var file = data.myFile; | |
var folder = DriveApp.getFolderById('1IxMiswEfi67ovoBf8ZH1RV7qVPx1Ks6l'); | |
var createFile = folder.createFile(file); | |
return createFile.getUrl(); | |
} | |
//HTML. Need to be pasted on the index.html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<title>Upload Files</title> | |
</head> | |
<body> | |
<h1>File Uploader</h1> | |
<form> | |
<input type="file" name="myFile" mulitple> | |
<br> | |
<br> | |
<input type="button" id="submitBtn" value="Upload Files"> | |
<label id="resp"></label> | |
</form> | |
<script> | |
document.getElementById('submitBtn').addEventListener('click', | |
function(e){ | |
google.script.run.withSuccessHandler(onSuccess).uploadFiles(this.parentNode) | |
}) | |
function onSuccess(data){ | |
document.getElementById('resp').innerHTML = "File Uploaded to the path " +data; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment