A small Python utility to upload a local file to Google Drive. The script checks whether the target folder exists and creates it if needed, then uploads or overwrites the specified file.
- Upload a local file to a Google Drive folder
- Automatically create the target folder if it does not exist
- Reuse existing file on Drive and overwrite it if found
- Load upload settings from
config.json
- Python 3.8+
PyDrive- Google Drive API credentials
- Install dependencies:
pip install pydrive- Create a Google API project and enable the Google Drive API.
- Download the OAuth client secrets file and save it as
client_secrets.jsonin the repository root. - Create
credentials.jsonusing PyDrive authentication or copy it from an existing authenticated session. - Copy
config.example.jsontoconfig.jsonand update the values:
{
"remote_file_name": "desired_remote_file_name.txt",
"remote_folder_name": "desired_remote_folder_name",
"local_file_name": "local_file_to_be_loaded.txt"
}Run the uploader script from the repository root:
python Gdrive_uploader.py- Do not commit
client_secrets.json,credentials.json, orconfig.jsonto a public repository. - The script currently expects
credentials.jsonto exist before running. - If multiple files or folders have the same name on Drive, the script uses the first match found.