camel-component-file
File component for rust-camel
Overview
The File component provides file system integration for rust-camel. It can read files from directories (consumer) and write files to directories (producer), supporting various file handling strategies.
Features
- Consumer: Poll directories for new files
- Producer: Write files with various strategies
- File filtering: Include/exclude patterns (regex)
- Post-processing: Delete, move, or no-op after processing
- Recursive directory scanning
- Atomic writes: Temp file prefix support
- Security: Path traversal protection
Installation
Add to your Cargo.toml:
[]
= "0.2"
URI Format
file:directoryPath[?options]
Consumer Options
| Option | Default | Description |
|---|---|---|
delay |
500 |
Poll interval in milliseconds |
initialDelay |
1000 |
Initial delay before first poll |
noop |
false |
Don't delete or move files after processing |
delete |
false |
Delete files after processing |
move |
.camel |
Directory to move processed files to |
include |
- | Regex pattern for files to include |
exclude |
- | Regex pattern for files to exclude |
recursive |
false |
Scan subdirectories |
fileName |
- | Only process files matching this name |
readTimeout |
30000 |
Timeout for reading files (ms) |
Producer Options
| Option | Default | Description |
|---|---|---|
fileName |
- | Output file name (or use CamelFileName header) |
fileExist |
Override |
Strategy: Override, Append, Fail |
tempPrefix |
- | Temp file prefix for atomic writes |
autoCreate |
true |
Create directories automatically |
writeTimeout |
30000 |
Timeout for writing files (ms) |
Usage
Consumer: Read Files
use RouteBuilder;
use FileComponent;
let route = from
.log
.to
.build?;
Consumer: Delete After Processing
let route = from
.process
.build?;
Consumer: Move After Processing
let route = from
.to
.build?;
Consumer: Filter by Pattern
// Only process .csv files
let route = from
.to
.build?;
Producer: Write Files
let route = from
.set_body
.set_header
.to
.build?;
Producer: Append Mode
let route = from
.set_header
.to
.build?;
Producer: Atomic Writes
let route = from
.set_header
.to
.build?;
Exchange Headers
Consumer Headers
| Header | Description |
|---|---|
CamelFileName |
Relative file path |
CamelFileNameOnly |
File name only |
CamelFileAbsolutePath |
Absolute file path |
CamelFileLength |
File size in bytes |
CamelFileLastModified |
Last modified timestamp |
Producer Headers
| Header | Description |
|---|---|
CamelFileName |
Output file name (required if no fileName option) |
CamelFileNameProduced |
Absolute path of written file |
Example: File Pipeline
use RouteBuilder;
use FileComponent;
use CamelContext;
async
Security
The File component includes protection against path traversal attacks. Attempts to write files outside the configured directory (e.g., using ../ in the filename) will be rejected with an error.
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.