Skip to content

WebNinjaDeveloper.com

Programming Tutorials




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

How to Upload Files to Google Drive Using Python 3 Using Google Drive API V3 Full Project

Posted on December 14, 2022

 

 

Welcome folks today in this blog post we will be uploading files to drive using the google drive v3 in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

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

 

 

app.py

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import json
import requests
headers = {
    "Authorization":"Bearer ###youraccesstoken###"
}
 
para = {
    "name":"kane.jpg",
    "parents":[""]
}
 
files = {
    'data':('metadata',json.dumps(para),'application/json;charset=UTF-8'),
    'file':open('./kane.jpg','rb')
}
 
r = requests.post("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
    headers=headers,
    files=files
)

 

 

As you can see you need to replace the accessToken of your google account. This can be captured inside the google oauth2 playground. And the we are declaring the path of the image to be uploaded to google drive. And then we are setting the metadata of the uploaded file such as the name and then actual image file is first of all opened using the open() method and then we are making a POST Request to the google drive api v3 and passing the headers and the actual files which is selected by the user.

Recent Posts

  • 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
  • Android Java Project to Download Random Image From Unsplash Using OkHttp & Picasso Library & Display it
  • 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