Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Google Apps Script to Upload Image to Google Drive Using HTML5 Forms in Browser Full Example

Posted on January 12, 2023

 

 

 

Welcome folks today in this blog post we will be uploading images to google drive using html5 forms in browser using javascript.All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an code.gs file and copy paste the following code

 

 

code.gs

 

 

JavaScript
1
2
3
function doGet() {
  return HtmlService.createHtmlOutputFromFile('form.html');
}

 

 

As you can see we are loading the form.html template file inside the browser we need to create the index.html file

 

 

index.html

 

 

1
2
3
4
<form>
  <input type="file" name="imageFile">
  <input type="submit" value="Upload" onclick="google.script.run.upload(this.parentNode)">
</form>

 

 

 

 

code.gs

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
function upload(e) {
  let destination_id = "1tjw5ZbZnU8aI263ZBMLFm8Z9qJMX5W8j"
 
  let img = e.imageFile
 
  let contentType = "image/jpeg"
 
  let destination = DriveApp.getFolderById(destination_id)
 
  destination.createFile(img)
 
}

 

 

Here you need to replace the drive folder id inside your drive as shown below

 

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme