Overview
Composio provides automatic file handling capabilities for tools that work with files. The SDK can automatically upload files before tool execution and download files from tool responses, making file operations seamless and transparent.Automatic File Handling
Enabling Auto Upload/Download
File handling is enabled by default in Composio. You can control this behavior during SDK initialization:How It Works
WhenautoUploadDownloadFiles is enabled:
- Before Execution: Files in tool parameters are automatically uploaded to Composio’s S3 storage
- During Execution: S3 URLs are passed to the tool instead of file content
- After Execution: Files in the response are automatically downloaded and converted to appropriate formats
Uploading Files
Manual File Upload
You can manually upload files using the Files API:Upload from URL
Upload File Object (Browser)
Using Uploaded Files in Tools
After uploading, use the file URL in tool execution:Downloading Files
Manual File Download
Download files from S3 URLs in tool responses:Save Downloaded Files
Automatic File Handling with Tools
WhenautoUploadDownloadFiles is enabled, files are handled automatically:
Example: Uploading a File to Google Drive
Example: Downloading a File from Google Drive
File Tool Modifier
The automatic file handling is implemented using the FileToolModifier internally. This modifier:- Before Execution: Scans tool parameters for file paths or File objects and uploads them to S3
- After Execution: Scans response data for S3 URLs and downloads the files
How It Works Internally
Supported File Types
Composio supports various file types:- Documents: PDF, DOCX, TXT, MD, etc.
- Images: PNG, JPG, JPEG, GIF, SVG, etc.
- Spreadsheets: XLSX, CSV, etc.
- Archives: ZIP, TAR, GZ, etc.
- Code: JS, TS, PY, etc.
- Media: MP3, MP4, etc.
File Size Limits
Best Practices
Enable Auto Handling
Use
autoUploadDownloadFiles: true for seamless file operations in most cases.Validate File Types
Validate file types and sizes before uploading to prevent errors.
Handle Errors
Implement proper error handling for file upload/download failures.
Clean Up Files
Delete temporary files after use to free up storage.
Working with Different File Sources
Local Files (Node.js)
Remote URLs
Base64 Encoded Files
Browser File Input
Error Handling
Advanced: Custom File Processing
If you need custom file processing, disable auto handling and use modifiers:Platform-Specific Considerations
Node.js
Browser
Cloudflare Workers
Next Steps
Tool Execution
Execute tools that work with files
Modifiers
Customize file handling with modifiers
Error Handling
Handle file-related errors
Custom Tools
Create custom tools that work with files