Overview
In this example, you’ll learn how to:- Pass file paths to tools that support attachments
- Send emails with file attachments using Gmail
- Work with local file paths in tool arguments
Prerequisites
1
Install dependencies
2
Set up environment variables
Create a
.env file with your API key:3
Connect your Gmail account
Use Composio CLI to authenticate with Gmail:This will open a browser window for OAuth authentication.
Complete Example
How It Works
1
Initialize Composio
Create a Composio instance with your API key.
2
Fetch Gmail Tool
Get the
GMAIL_SEND_EMAIL tool which supports file attachments.3
Prepare File Path
Use Node’s
path module to construct the absolute path to your file. Composio handles reading and encoding the file.4
Execute with Attachment
Pass the file path in the
attachment parameter. Composio automatically:- Reads the file from the filesystem
- Encodes it appropriately (base64 for email)
- Includes it in the API request
Tool Parameters
string
Absolute or relative file path to the attachment
string
required
Email address of the recipient
string
required
Email subject line
string
required
Email body content (plain text or HTML)
string
Gmail user ID (use ‘me’ for authenticated user)
Expected Output
Supported File Types
Composio automatically handles various file types based on the tool:Email Attachments (Gmail, Outlook)
Email Attachments (Gmail, Outlook)
- Images:
.png,.jpg,.jpeg,.gif,.bmp - Documents:
.pdf,.doc,.docx,.txt - Spreadsheets:
.xls,.xlsx,.csv - Presentations:
.ppt,.pptx - Archives:
.zip,.tar,.gz
File Upload Tools (Drive, Dropbox)
File Upload Tools (Drive, Dropbox)
All file types are supported. The tool will preserve the original file format and metadata.
Image Processing Tools
Image Processing Tools
Specific image formats depending on the tool (typically
.png, .jpg, .jpeg, .webp)Multiple Attachments
Some tools support multiple attachments. Check the tool schema:URL-Based File Handling
You can also pass URLs for some tools:Error Handling
Best Practices
Use Absolute Paths: Always use absolute paths or resolve relative paths using
path.join() or path.resolve()Check File Size: Be aware of size limits for different services (e.g., Gmail has a 25MB limit)
Validate File Exists: Check if the file exists before attempting to send it
Handle Errors: Always wrap file operations in try-catch blocks to handle missing files or permission errors
Next Steps
Custom Tools
Create custom tools with file handling
OpenAI Example
Combine file handling with AI agents