Overview
The pfx-filepreview component generates structured previews of CSV and XLSX files. It reads a configurable number of rows, auto-detects column types (STRING, NUMBER, INTEGER, BOOLEAN, DATE, DATE_TIME), and returns a JSON preview. Supports compressed (ZIP), base64-encoded, and plain inputs.
URI pattern: pfx-filepreview:preview[?options]
Method
|
Method |
Description |
|---|---|
|
|
Generate a JSON column/row preview from the input file |
Parameters
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
String |
— |
Required. |
|
|
Integer |
|
Max data rows to include in preview (header excluded) |
|
|
String |
— |
Character encoding for CSV ( |
|
|
String |
|
CSV column delimiter (practical default from parser) |
|
|
String |
|
CSV quote character (practical default from parser) |
|
|
String |
|
CSV escape character (practical default from parser) |
|
|
boolean |
|
Generate virtual headers ( |
|
|
String |
|
Decimal separator for number parsing (practical default from parser; use |
|
|
String |
|
Java DateTimeFormatter pattern for date parsing (practical default from parser) |
|
|
boolean |
|
Decode body from base64 before processing |
|
|
boolean |
|
Return the preview JSON (or raw CSV lines) as base64 |
|
|
String |
|
Where to store result: |
|
|
String |
— |
Header/property name when |
Output Headers
|
Header |
Type |
Description |
|---|---|---|
|
|
String |
File type processed ( |
|
|
Integer |
Actual number of records in the preview |
Output Format
{
"fileName": "products.csv",
"columns": [
{
"name": "sku",
"type": "STRING",
"order": 0,
"parsedValues": ["SKU001", "SKU002", "SKU003"],
"originalValues": ["SKU001", "SKU002", "SKU003"]
},
{
"name": "price",
"type": "NUMBER",
"order": 1,
"parsedValues": [29.99, 149.50, 89.00],
"originalValues": ["29.99", "149.50", "89.00"]
}
]
}
Examples
Preview CSV from inbound directory
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="previewCsv">
<from uri="file:{{inbound.path}}?noop=true&include=.*\.csv"/>
<to uri="pfx-filepreview:preview?fileType=CSV&maxRecords=5"/>
<log message="Preview: ${body}"/>
</route>
</routes>
Preview XLSX, store result in header (preserve body)
<to uri="pfx-filepreview:preview?fileType=XLSX&maxRecords=3&storeResultTo=header&storeResultToName=previewJson"/>
<!-- body still contains original file; header.previewJson has the JSON -->
European CSV (semicolon delimiter, comma decimal)
<to uri="pfx-filepreview:preview?fileType=CSV&separator=;&decimalSeparator=,&dateFormat=dd.MM.yyyy"/>
Base64 input/output (for API transport)
<to uri="pfx-filepreview:preview?fileType=CSV&inputBase64Encoded=true&resultAsBase64=true"/>
Column Type Detection
Types are detected in this precedence order (first match wins):
|
Type |
Rule |
|---|---|
|
|
All non-empty values parse as LocalDateTime |
|
|
All non-empty values parse as LocalDate |
|
|
All non-empty values are |
|
|
All non-empty values parse as decimal |
|
|
Default fallback |
Empty values are ignored during type detection. A column with all-empty values defaults to STRING.
Common Pitfalls
-
fileTypeis required — the component does not auto-detect file format. -
ZIP-compressed files are decompressed automatically — no special configuration needed.
-
When
storeResultTo=header, you must also setstoreResultToName. -
Keep
maxRecordslow (≤20) for preview use cases — the component reads the full file for type detection but stops collecting rows aftermaxRecords. -
For XLSX, the first sheet (index 0) is always used.
-
specifiedCharsetis optional — the component will attempt charset auto-detection if not provided. Set it explicitly when you know the encoding to avoid misdetection.