Upload Files to Google Drive using Google Drive API and Flask

Obi kastanya
2 min readOct 29, 2022

--

drive.google.com

Next, we gonna upload a file to Google Drive using Google Drive API.

Use the codebase we created in the previous tutorials.

Now write The following code in main.py files.

Before we could upload the files, we need to load the files into memory as a buffer using the BytesIO library.

Then we wrap it with MediaIoBaseUpload so GoogleApiClient could easily process our files/media.

Now, let's check the API.

Create a request using postman and give it a payload with form-data types.

Then hit the API endpoint.

This is how it's gonna look when we hit the API.

We could also change the file metadata through the ‘body’ parameters. For example, as we could see from the code, we changed the file name to add created_at datetime in the title to make the filename unique.

Furthermore, we could also add custom properties for our Google Drive Files.

Give a change to the main.py files.

Now change the postman request, add a new payload named description then check the API.

Fantastic, now the files have custom properties.

Give me a clap if you like my articles. If you want to see the full code, visit my GitHub repository here.

Previous Article: 6 Fundamental Query to Your Google Drive API (Using Flask)
Next Article: Delete Files in Google Drive using Google Drive API and Flask

--

--

Obi kastanya
Obi kastanya

Written by Obi kastanya

Python Developer | Backend Developer | Medium Writer

No responses yet