Overview
The File Type Detector node analyzes binary file data to determine the file type by inspecting its "magic bytes" (signature bytes at the start of a file). This detection method is more reliable than relying solely on file extensions or MIME types provided externally. The node can also fall back to using the original MIME type if detection fails and optionally categorize the detected file type into broad categories like image, document, video, etc.
This node is useful in workflows where you receive files with unknown or unreliable metadata and need to programmatically identify their true format for further processing, routing, or validation. For example:
- Automatically detecting uploaded file types before conversion or storage.
- Validating that incoming files match expected formats.
- Categorizing files for conditional workflow branching.
Properties
| Name | Meaning |
|---|---|
| Binary Property | Name of the binary property containing the file data to analyze (default: data). |
| Fallback to Original MIME Type | Whether to use the original MIME type from the binary data if magic byte detection fails (true/false). |
| Include File Categories | Whether to include a categorized file type label such as image, document, video, audio, etc. (true/false). |
Output
The node outputs the input items augmented with a new JSON field fileTypeAnalysis containing details about the detected file type:
originalMimeType: The MIME type originally associated with the binary data (or"unknown"if none).fileName: The original file name if available (or"unknown").fileSize: Size of the binary data in bytes.detectionMethod: Either"magic-bytes"if detection succeeded or"fallback"if it used the original MIME type.confident: Boolean indicating whether detection was confident (true if magic byte detection succeeded).detectedMimeType: The MIME type detected from the file content or fallback.detectedExtension: The file extension corresponding to the detected MIME type (e.g.,jpg,pdf,bin).fileCategory(optional): A broad category of the file type such asimage,document,video,audio,archive,code, orother.
If the node encounters an error and is configured to continue on failure, the output item will contain an error field describing the issue.
The binary data itself is passed through unchanged.
Dependencies
- Uses the external library
file-typeto perform magic byte analysis. - Requires the input item to have binary data accessible under the specified binary property.
- No external API keys or services are required.
Troubleshooting
- No binary data found in property "X": This error occurs if the specified binary property does not exist or contains no data in the current item. Ensure the binary property name matches exactly and that the input contains valid binary data.
- Detection falls back to original MIME type: If the magic byte detection fails, the node uses the original MIME type if enabled. If this is unexpected, verify that the binary data is complete and correctly encoded.
- Unknown file extension or category: Some rare or unsupported file types may be labeled as
"unknown"or"other". Consider updating the node or handling these cases explicitly downstream. - If the node throws errors and you want the workflow to continue processing other items, enable the "Continue On Fail" option in the node settings.
Links and References
- file-type npm package — Library used for magic byte detection.
- Magic numbers - Wikipedia — Explanation of file signature bytes used for detection.