Trying to created a Google Apps Script to prompt me to choose a file to upload to Google Drive as described here
But I am receiving an error
Uncaught ScriptError: TypeError: Cannot read property 'getAs' of undefined
I have watched the YouTube video a couple of times now, but I don't see that I am doing anything incorrectly. Any ideas?
function doGet(){
return HtmlService.createHtmlOutputFromFile("form.html")
}
function upload(e){
// logic to upload the file
var destination_id = 'enter your folder id here' //folder id
var img = e.imageFile
var contentType = 'img/png'
var destination = DriveApp.getFolderById(destination_id)
var img = img.getAs(contentType)
destination.createFile(img)
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
<input type="file" name="imageFile"/>
<input type="button" value="Upload" onclick="google.script.run.upload(this.parentNode)">
</form>
</body>
</html>