Skip to content

Instantly share code, notes, and snippets.

@sean-perryman
Created August 10, 2018 02:42
Show Gist options
  • Save sean-perryman/b4dc3b865500a2a14f2cbab858015c9b to your computer and use it in GitHub Desktop.
Save sean-perryman/b4dc3b865500a2a14f2cbab858015c9b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Sample script for uploading file to Google Drive without authorization</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.js"></script>
</head>
<body>
<form action="https://script.google.com/macros/s/#####/exec" id="form" method="post">
Upload a file
<div id="data"></div>
<input name="file" id="uploadfile" type="file" multiple>
<input id="submit" type="submit">
</form>
<script>
$('#uploadfile').on("change", function() {
for (var i = 0; i > files.length; i++) {
var file = this.files[i];
var fr = new FileReader();
fr.fileName = file.name;
fr.onload = function(e) {
e.target.result
html = '<input type="hidden" name="data" value="' + e.target.result.replace(/^.*,/, '') + '" >';
html += '<input type="hidden" name="mimetype" value="' + e.target.result.match(/^.*(?=;)/)[0] + '" >';
html += '<input type="hidden" name="filename" value="' + e.target.fileName + '" >';
$("#data").empty().append(html);
}
fr.readAsDataURL(file);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment