I've modified this script to upLoad a file to a folder in my google drive. But I also need it to return the url link of that uploaded file back into to a span or a form field.
I can't get it to return the url link.
So far I this is what my code looks like.
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
<label>INCLUIR IMAGEM</label><input type="file" accept="image/*" capture="camera" name="imageFile"/>
<!-- <input type="file" name="imageFile">-->
<input type="button" value="Upload File"
onclick="google.script.run.withSuccessHandler(updateUrl).upload(this.parentNode)">
</form><br/><br/>
<div id="output"></div>
</body>
</html>
<script>
function updateUrl(imageUrl) {
var div = document.getElementById('output');
div.innerHTML = '<span>' + imageUrl +'</span>';
}
</script>
code.gs
function upload(e) {
// Folder ID of destination folder
var destination_id = '1qghuk1-kShw8NMJLhzmRGJJwM-dHVJ5t';
var contentType = 'image/jpeg';
var imageUrl = e.imageFile;
var destination = DriveApp.getFolderById(destination_id);
destination.createFile(imageUrl);
var folder = destination.next();
var files = folder.getFiles();
if (files.hasNext()) {
// For this test, use first found file
var file = files.next();
var imageUrl = Drive.Files.get(file.getId()).webContentLink;
Logger.log(imageUrl);
return imageUrl;
}
}