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>