Uploading a file to GoogleDrive using GoogleAppsScript(GAS)

Hello, I’m “Iori Nitta.”

This time, I will create a simple application using Google Apps Script (GAS) to upload files to Google Drive.


function doGet() {
  const htmlOutput = HtmlService.createTemplateFromFile('index').evaluate();
  return htmlOutput;

// post Data from Html
function postForm(formObject) {
  const blob = formObject.file;

  const folder_id = '< GoogleDrive Folder ID >'; // Google Drive's FolderID
  const folder = DriveApp.getFolderById(folder_id);


<!DOCTYPE html>
<html lang="ja">
    <meta charset="utf-8">
    <base target="_top">

    <form id="upload_form" onsubmit="handleFormSubmit(this)">
        <input id="file_input" name="file" type="file"><br>
        <input id="upload_button" type="submit" value="アップロード">
    <div id="message" class="center"></div>

      Created by: <a href="https://nitta-iori.com/">新田いおり</a>


  body {
    text-align: center;


  function preventFormSubmit() {
    const upload_form = document.getElementById("upload_form");
    upload_form.addEventListener("submit", e => {

  // post Data
  function handleFormSubmit(formObject) {
    const file = formObject.file;
    const len = file.files.length;
    const size = file.files[0].size;
    const maxSize = 1024 * 1024 * 50; // max 50MB

    if (len === 1 && size <= maxSize) {
      const message_div = document.getElementById("message");
      message_div.innerHTML="Uploading ...";

  // finished upload
  function updateMessage() {
    const message_div = document.getElementById("message");
    message_div.innerHTML = "Success Uploaded.";

  window.addEventListener("load", preventFormSubmit);


With this, we have completed a simple application to send files to Google Drive.

By deploying it to a publicly accessible site, you can create a convenient platform for sharing videos and files with friends.

I hope this helps those who are using GAS for development. Thank you for your support, and please feel free to reach out in the future.

Leave a Comment