Skip to content

Instantly share code, notes, and snippets.

@MdKutubuddinSardar
Created March 11, 2018 09:24
Show Gist options
  • Save MdKutubuddinSardar/27495940a9cb135149743cd1dbcfcf3e to your computer and use it in GitHub Desktop.
Save MdKutubuddinSardar/27495940a9cb135149743cd1dbcfcf3e to your computer and use it in GitHub Desktop.
uploading file to Google Drive without authorization
<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/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/exec" enctype="multipart/form-data" id="form" method="post" onsubmit="return checkSize(2097152)">
Upload a file
<div id="data">
</div>
<input id="uploadfile" name="file" type="file" />
<input id="submit" type="submit" />
</form>
<script type="text/javascript">
function checkSize(max_img_size)
{
var input = document.getElementById("uploadfile");
// check for browser support (may need to be modified)
if(input.files && input.files.length == 1)
{
if (input.files[0].size > max_img_size)
{
alert("The file must be less than " + (max_img_size/1024/1024) + "MB");
return false;
}
}
return true;
}
$('#uploadfile').on("change", function() {
var file = this.files[0];
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>
@datepickerUser
Copy link

Hi-This is a good script - However when it is run it executes the script and the results come in another page.
I want to use it on a static html page on my computer - so it should not go to any other page but give the result into a <div id="result" on my page.
how to get the server response into my static html page
thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment