Skip to content

lamtx/gg-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Drive Uploader - Rust Console Application

A Rust console application that uploads files to Google Drive using a service account for authentication.

Features

  • Upload files to Google Drive using service account authentication
  • Support for custom file names in Google Drive
  • Optional parent folder specification
  • Automatic MIME type detection
  • Clean command-line interface with clap
  • Comprehensive error handling

Prerequisites

  1. Google Cloud Project: You need a Google Cloud Project with the Google Drive API enabled.

  2. Service Account: Create a service account in your Google Cloud Project and download the JSON key file.

  3. Enable Google Drive API:

    • Go to the Google Cloud Console
    • Navigate to "APIs & Services" > "Library"
    • Search for "Google Drive API" and enable it

Setup Instructions

1. Create a Service Account

  1. Go to the Google Cloud Console
  2. Select your project (or create a new one)
  3. Navigate to "IAM & Admin" > "Service Accounts"
  4. Click "Create Service Account"
  5. Fill in the details and click "Create and Continue"
  6. Skip the optional steps and click "Done"
  7. Click on your newly created service account
  8. Go to the "Keys" tab
  9. Click "Add Key" > "Create new key"
  10. Select "JSON" format and click "Create"
  11. Save the downloaded JSON file securely

2. Share Google Drive Folder (Optional)

If you want to upload to a specific folder:

  1. Create a folder in Google Drive
  2. Share the folder with your service account email (found in the JSON key file)
  3. Copy the folder ID from the URL when viewing the folder

3. Build and Run

# Clone or create the project
cargo build --release

# Run the application
cargo run -- --help

Usage

Basic Usage

Upload a file to the root of Google Drive:

cargo run -- \
  --service-account-key /path/to/service-account-key.json \
  --file-path /path/to/your/file.txt

Advanced Usage

Upload with custom name and parent folder:

cargo run -- \
  --service-account-key /path/to/service-account-key.json \
  --file-path /path/to/your/file.txt \
  --name "My Custom File Name.txt" \
  --parent-folder-id "1ABCDEfghIJKLmnoPQRstUVwxYZ"

Command Line Options

  • -s, --service-account-key <PATH>: Path to the service account JSON key file (required)
  • -f, --file-path <PATH>: Path to the file to upload (required)
  • -n, --name <NAME>: Custom name for the file in Google Drive (optional)
  • -p, --parent-folder-id <ID>: Parent folder ID in Google Drive (optional)

Example Output

Authenticating with Google Drive...
Uploading file: /home/user/document.pdf
✓ File uploaded successfully!
  File ID: 1XYZabcDEFghiJKLmnoPQRstUVwxyz
  File Name: document.pdf
  View Link: https://drive.google.com/file/d/1XYZabcDEFghiJKLmnoPQRstUVwxyz/view

Security Notes

  • Keep your service account key file secure and never commit it to version control
  • Consider using environment variables or secure secret management for production use
  • The service account only has access to files it creates unless explicitly shared

Troubleshooting

Common Issues

  1. "Failed to decode private key": The private key in your JSON file might be malformed. Re-download the service account key.

  2. "Token request failed": Check that your service account key is valid and the Google Drive API is enabled.

  3. "File not found": Verify the file path is correct and the file exists.

  4. "Upload failed": Check your internet connection and that the service account has the necessary permissions.

Getting Folder IDs

To get a folder ID for the --parent-folder-id option:

  1. Open Google Drive in your browser
  2. Navigate to the desired folder
  3. Look at the URL: https://drive.google.com/drive/folders/FOLDER_ID_HERE
  4. Copy the folder ID from the URL

Dependencies

  • tokio: Async runtime
  • reqwest: HTTP client with multipart support
  • serde: Serialization/deserialization
  • jsonwebtoken: JWT token creation for OAuth
  • clap: Command-line argument parsing
  • anyhow: Error handling
  • chrono: Date/time handling
  • mime_guess: MIME type detection

License

This project is provided as-is for educational and practical purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages