Upload a file to Google Drive
The Anvil Google API Service gives you a simple way to use a range of Google services.
In this quickstart, we’ll build an app that uploads files to your Google Drive.
Log in to Anvil and click ‘New Blank App’. Choose the Material Design theme.
In the App Browser, click the + next to Services.
You’ll see a list of available services and integrations. Click on Google API.
In the Sidebar Menu, click the blue plus button . You’ll see a list of available services and integrations. Click on Google API.
If you don’t have a Google account, you need to create one - it’s free and they’re really useful.
Create an empty folder:
Go back to the Anvil Editor.
In the Google API Service, click the Add App File button:
A Google login dialog will open in a separate browser window. Log in to see this dialog in the Anvil Editor:
Browse your Google Drive and select the folder you created earlier.
It will be displayed in the Google API Service like this:
Go to the Design View for Form1. Drag-and-drop a FileLoader component into your app.
Double-click the FileLoader in the Design View to configure a
change event. This code will be automatically written
for you in the Code View:
def file_loader_1_change(self, file, **event_args): """This method is called when a new file is loaded into this FileLoader""" pass
pass and write this line in its place:
my_folder_name is the name of the Google Drive folder you added to the app. In my case, that’s
Run your app:
Click on the Upload button, select a file from your computer and hit ‘open’:
Check your Google Drive - the file you uploaded will be in the folder:
Click on the button below to clone a finished version of this app into your account.
The cloned version will not have the permissions that were granted to the original, of course!
You’ll need to click the button to set up your own Google account, and add your own files rather than ours:
Want more depth on this subject?
There’s much more to the Google API Service.
- You can do much more with your Google Drive files
- You can log users in to your app with their Google accounts
- And you can access your users Google Drive files
Want another quickstart?
Every quickstart is on the Quickstarts page.
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.