Skip to main content

What Are Custom Extractors?

Custom extractors are specialized plugins that enable you to handle file formats that aren’t natively supported by Flatfile’s existing plugins. They process uploaded files, extract structured data, and provide that data for mapping into Sheets as Records. This guide covers everything you need to know to build custom extractors. Common use cases include:
  • Legacy system data exports (custom delimited files, fixed-width formats)
  • Industry-specific formats (healthcare, finance, manufacturing)
  • Multi-format processors (handling various formats in one extractor)
  • Binary file handlers (images with metadata, proprietary formats)

Architecture Overview

Core Components

Custom extractors are built using the @flatfile/util-extractor utility, which provides a standardized framework for file processing:
Once you’ve created your extractor, you must register it in a listener to be used. This will ensure that the extractor responds to the file:created event and processes your files.

Handling Multiple File Extensions

To support multiple file extensions, use a RegExp pattern:

Key Architecture Elements

ComponentPurposeRequired
File ExtensionString or RegExp of supported file extension(s)
Extractor TypeString identifier for the extractor type
Parser FunctionCore logic that converts file buffer to structured data
OptionsConfiguration for chunking, parallelization, and customization-

Data Flow

  1. File Upload → Flatfile receives file with matching extension
  2. Event Triggerfile:created event fires
  3. Parser Execution → Your parser function processes the file buffer
  4. Data Structuring → Raw data is converted to WorkbookCapture format and provided to Flatfile for mapping into Sheets as Records
  5. Job Completion → Processing status is reported to user

Getting Started

Remember that custom extractors are powerful tools for handling unique data formats. Start with simple implementations and gradually add complexity as needed.

Prerequisites

Install the required packages. You may also want to review our Coding Tutorial if you haven’t created a Listener yet.

Basic Implementation

Let’s create a simple custom extractor for a pipe-delimited format. This will be used to process files with the .pipe or .psv extension that look like this:
And now let’s import and register it in your Listener.
That’s it! Your extractor is now registered and will be used to process pipe-delimited files with the .pipe or .psv extension.

Advanced Examples

Multi-Sheet Parser

Let’s construct an Extractor to handle files that contain multiple data sections. This will be used to process files with the .multi or .sections extension that look like this:
Now let’s register it in your Listener.

Binary Format Handler

This example will be used to process binary files with structured data. This will be used to process binary files with the .bin or .dat extension. Due to the nature of binary format, we can’t easily present a sample import here.
And, once again, let’s register it in your Listener.

Configuration-Driven Extractor

Create a flexible extractor that can be configured for different formats. This will be used to process files in a manner that handles different delimiters, line endings, and other formatting options.
Now let’s register two different configurable extractors in our Listener. The first will be used to process files with the .custom extension that look like this, while transforming dates and amount values:
The second will be used to process files with the .pipe or .special extension that look like this:

Reference

API

ParameterTypeDescription
fileExtstring or RegExpFile extension to process (e.g., ".custom" or /\.(custom|special)$/i)
extractorTypestringIdentifier for the extractor type (e.g., “custom”, “binary”)
parseBufferParserFunctionFunction that converts Buffer to WorkbookCapture
optionsRecord<string, any>Optional configuration object

Options

OptionTypeDefaultDescription
chunkSizenumber5000Records to process per batch
parallelnumber1Number of concurrent processing chunks
debugbooleanfalseEnable debug logging

Parser Function Options

Your parseBuffer function receives additional options beyond what you pass to Extractor:
OptionTypeDescription
fileIdstringThe ID of the file being processed
fileExtstringThe file extension (e.g., “.csv”)
headerSelectionEnabledbooleanWhether header selection is enabled for the space

Data Structures

WorkbookCapture Structure

The parser function must return a WorkbookCapture object:

Cell Value Objects

Each cell value should use the Flatfile.RecordData format:

Message Types

TypeDescriptionUI Effect
errorValidation errorRed highlighting, blocks Actions with the hasAllValid constraint
warningWarning messageYellow highlighting, allows submission
infoInformational messageMouseover tooltip, allows submission

TypeScript Interfaces

Troubleshooting Common Issues

Files Not Processing

Symptoms: Files upload but no extraction occurs Solutions:
  • Verify file extension matches fileExt configuration
  • Check Listener is properly deployed and running
  • Enable debug logging to see processing details

Parser Errors

Symptoms: Jobs fail with parsing errors Solutions:
  • Add try-catch blocks in parser function
  • Validate input data before processing
  • Return helpful error messages

Memory Issues

Symptoms: Large files cause timeouts or memory errors Solutions:
  • Reduce chunk size for large files
  • Implement streaming for very large files
  • Use parallel processing carefully

Performance Problems

Symptoms: Slow processing, timeouts Solutions:
  • Optimize parser algorithm
  • Use appropriate chunk sizes
  • Consider parallel processing for I/O-bound operations