Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

FileToFileContent

Converts local files into FileContent objects that can be embedded into ChatMessage objects and passed to an LLM.

Key Features

  • Converts local files into FileContent objects containing base64-encoded file data, MIME type, and filename
  • Automatically detects the MIME type of each file
  • Skips empty files with a warning instead of failing
  • Supports optional provider-specific extra information for each file
  • Enables passing files directly to an LLM to ask questions about their content

Configuration

  1. Drag the FileToFileContent component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. Configure the parameters as needed.

Connections

FileToFileContent receives file paths or ByteStream objects as input — typically from FileTypeRouter. It outputs a list of FileContent objects that you can send to ChatPromptBuilder for inclusion in chat messages passed to an LLM.

Usage Example

Using the Component in a Pipeline

In this pipeline, FileToFileContent converts files and passes them to a chat generator through a ChatPromptBuilder:

components:
FileToFileContent:
type: haystack.components.converters.file_to_file_content.FileToFileContent
init_parameters: {}
ChatPromptBuilder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
template:
- _content:
- text: "Analyze the following files and answer questions about them."
_role: system
- _content:
- text: "{{ query }}"
_role: user
required_variables:
variables:
ChatGenerator:
type: haystack.components.generators.chat.openai.OpenAIChatGenerator
init_parameters:
model: gpt-4o
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false

connections:
- sender: FileToFileContent.file_contents
receiver: ChatPromptBuilder.file_contents
- sender: ChatPromptBuilder.prompt
receiver: ChatGenerator.messages

inputs:
files:
- FileToFileContent.sources
query:
- ChatPromptBuilder.query

outputs:
replies: ChatGenerator.replies

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]List of file paths or ByteStream objects to convert.
extraOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]NoneOptional extra information to attach to the FileContent objects. Can be used to store provider-specific information. Values should be JSON serializable. This value can be a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the extra of all produced FileContent objects. If it's a list, its length must match the number of sources as they're zipped together.

Outputs

ParameterTypeDefaultDescription
file_contentsList[FileContent]A list of FileContent objects created from the input files.

Init Parameters

This component has no init parameters.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]List of file paths or ByteStream objects to convert.
extraOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]NoneOptional extra information to attach to the FileContent objects. Can be used to store provider-specific information. Values should be JSON serializable. This value can be a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the extra of all produced FileContent objects. If it's a list, its length must match the number of sources as they're zipped together.