A Frappe app that automatically uploads file attachments to Google Drive, providing seamless cloud storage integration for your Frappe applications.
- Automatic Upload: Automatically uploads files to Google Drive when attachments are added
- Flexible Organization: Organizes files in customizable folder structures
- Privacy Controls: Supports both private and public file sharing
- Batch Migration: Migrate existing local files to Google Drive
- Service Account Integration: Uses Google Cloud Service Account for secure authentication
- Customizable Permissions: Configure file sharing permissions (private, public, specific users)
- Date-based Folders: Optional automatic date-based folder organization
- File Streaming: Stream files directly from Google Drive
- Automatic Cleanup: Optionally delete files from Google Drive when removed from Frappe
-
Install the app:
bench get-app https://github.com/your-repo/frappe-gdrive-attachment.git bench install-app frappe_gdrive_attachment
-
Install Python dependencies:
pip install google-api-python-client google-auth google-auth-oauthlib google-auth-httplib2
-
Create a Google Cloud Project:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Drive API
-
Create Service Account:
- Navigate to "IAM & Admin" → "Service Accounts"
- Create a new service account
- Download the JSON key file
- Grant necessary permissions to the service account
-
Configure Drive Access:
- Share your Google Drive folder with the service account email
- Or use the root drive if you have domain-wide delegation
-
Access Configuration:
- Go to "Google Drive Configuration" in your Frappe system
- This is a single doctype accessible to System Managers
-
Basic Settings:
- Enable Google Drive Upload: Check to activate the integration
- Delete file from Google Drive: Check to delete files from Drive when deleted in Frappe
-
Google Drive Credentials:
- Service Account Email: Auto-populated from JSON key
- Service Account Key (JSON): Paste the complete JSON key file content
- Parent Folder ID: Optional - Google Drive folder ID where files will be uploaded
- Folder Name Prefix: Optional prefix for organizing files
- Create Date-based Folders: Enable automatic YYYY/MM/DD folder structure
-
Sharing Settings:
- Private: Only service account can access
- Anyone with link can view: Public read access
- Anyone with link can edit: Public edit access
- Specific people: Restricted access to specified email addresses
All files are uploaded directly to the configured parent folder without creating nested folder structures. Files are organized using filename prefixes for easy identification:
Filename Structure:
[DocType]_[DocumentName]_[OriginalFilename]
Examples:
Customer_ABC Corp_contract.pdfProject_Website Redesign_mockup.jpgTask_Fix Bug 123_screenshot.png
This approach keeps all files in a single folder while maintaining clear organization through descriptive filenames.
Once configured, the app automatically:
- Intercepts file uploads in Frappe
- Uploads files to Google Drive
- Updates file URLs to point to Google Drive
- Removes local files to save server space
To migrate existing files:
- Go to "Google Drive Configuration"
- Click "Migrate Existing Files to Google Drive"
- Confirm the migration process
- Monitor the progress and check for any errors
- Private files: Accessed through Frappe's secure endpoint
- Public files: Direct Google Drive links
- Specific users: Shared with configured email addresses
# Test Google Drive connection
frappe.call({
method: "frappe_gdrive_attachment.controller.test_gdrive_connection"
})
# Get file information
frappe.call({
method: "frappe_gdrive_attachment.controller.get_drive_file_info",
args: { file_id: "your_file_id" }
})
# Migrate existing files
frappe.call({
method: "frappe_gdrive_attachment.controller.migrate_existing_files"
})# Get Google Drive settings
from frappe_gdrive_attachment.frappe_gdrive_attachment.doctype.google_drive_configuration.google_drive_configuration import get_google_drive_config
config = get_google_drive_config()You can customize the folder structure by creating a hook:
# In your custom app's hooks.py
doc_events = {
"File": {
"before_insert": "your_app.utils.custom_gdrive_folder_structure"
}
}Configure doctypes to ignore in site_config.json:
{
"ignore_gdrive_upload_for_doctype": ["Data Import", "Error Log"]
}- Service Account Security: Store service account keys securely
- Folder Permissions: Ensure proper Google Drive folder permissions
- Data Privacy: Configure appropriate file sharing settings
- Access Control: Limit System Manager access to configuration
-
Authentication Errors:
- Verify service account JSON key format
- Check Google Drive API is enabled
- Ensure service account has Drive access
-
Upload Failures:
- Check service account permissions
- Verify parent folder exists and is accessible
- Check network connectivity
-
File Access Issues:
- Verify file sharing permissions
- Check if files exist in Google Drive
- Ensure proper folder structure
Check Frappe error logs for detailed error messages:
- Navigate to "Error Log" in Frappe
- Look for Google Drive related errors
- Check the full stack trace for debugging
# Run tests
bench run-tests --app frappe_gdrive_attachment
# Test specific functionality
bench execute frappe_gdrive_attachment.controller.test_gdrive_connection- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
MIT License
For issues and support:
- Check the troubleshooting section
- Review error logs
- Create an issue on GitHub
- Contact support team
- Initial release
- Basic Google Drive integration
- File upload and organization
- Migration support
- Sharing permissions
- Service account authentication