JSPM

n8n-nodes-file-type-detector

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q46032F
  • License MIT

n8n node for detecting file types using magic bytes analysis

Package Exports

  • n8n-nodes-file-type-detector
  • n8n-nodes-file-type-detector/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (n8n-nodes-file-type-detector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

n8n-nodes-file-type-detector

Custom n8nnode File Type Detector

A powerful n8n community node that detects file types using magic bytes analysis, providing more reliable file type detection than MIME types alone.

Features

  • Magic Bytes Detection: Uses the file-type library to analyze file headers for accurate type detection
  • MIME Type Fallback: Falls back to original MIME type when magic bytes detection fails
  • File Categorization: Automatically categorizes files (image, document, video, audio, archive, etc.)
  • Comprehensive Analysis: Provides detailed file information including size, confidence level, and detection method
  • Error Handling: Robust error handling with continue-on-fail support

Installation

  1. Open your n8n instance
  2. Go to SettingsCommunity Nodes
  3. Click "Install a community node"
  4. Enter: n8n-nodes-file-type-detector
  5. Click Install

Via npm (Self-hosted n8n)

npm install n8n-nodes-file-type-detector

After installation, restart your n8n instance to load the new node.

Usage

Basic Workflow

The File Type Detector node works with binary data and is typically used in workflows that process files:

File Source → File Type Detector → Process Based on Type

Example Workflows

1. Analyze Uploaded Files

Webhook (File Upload) → File Type Detector → Switch (by file category)

2. Process Email Attachments

Email Trigger → File Type Detector → Route by File Type

3. Download and Analyze Files

HTTP Request (File Download) → File Type Detector → Store with Metadata

Node Configuration

Parameters

  • Binary Property (default: data): The name of the binary property containing the file data
  • Fallback to Original MIME Type (default: true): Whether to use the original MIME type if detection fails
  • Include File Categories (default: true): Whether to include categorized file types in the output

Output Format

The node adds a fileTypeAnalysis object to your data with the following structure:

{
  "fileTypeAnalysis": {
    "originalMimeType": "image/png",
    "fileName": "example.png",
    "fileSize": 12345,
    "detectionMethod": "magic-bytes",
    "confident": true,
    "detectedMimeType": "image/png",
    "detectedExtension": "png",
    "typeName": "png",
    "fileCategory": "image"
  }
}

Field Descriptions

Field Description
originalMimeType The original MIME type from the source
fileName The original filename (if available)
fileSize File size in bytes
detectionMethod Method used: "magic-bytes" or "fallback"
confident Boolean indicating confidence in detection
detectedMimeType The detected MIME type
detectedExtension The detected file extension
typeName The type name (e.g., "png", "pdf")
fileCategory File category (see categories below)

File Categories

The node categorizes files into the following types:

  • image: PNG, JPEG, GIF, BMP, WebP, SVG, etc.
  • document: PDF, DOC, DOCX, TXT, RTF, etc.
  • spreadsheet: XLS, XLSX, CSV, ODS, etc.
  • presentation: PPT, PPTX, ODP, etc.
  • video: MP4, AVI, MOV, WMV, etc.
  • audio: MP3, WAV, FLAC, AAC, etc.
  • archive: ZIP, RAR, 7Z, TAR, etc.
  • code: JS, HTML, CSS, Python, etc.
  • other: Files that don't fit other categories

Use Cases

1. File Upload Validation

Validate that uploaded files match expected types, regardless of file extension manipulation.

2. Content Processing Workflows

Route different file types to appropriate processing nodes (OCR for documents, thumbnail generation for images, etc.).

3. Security Scanning

Detect potentially malicious files that may have incorrect MIME types or extensions.

4. File Organization

Automatically organize files into folders based on their actual type rather than claimed type.

5. Data Pipeline Processing

Ensure data pipelines handle files correctly by knowing their true format.

Why Use Magic Bytes Detection?

Traditional MIME type detection can be unreliable because:

  • File extensions can be changed by users
  • Web servers may report incorrect MIME types
  • Email systems may modify MIME types
  • Malicious files may claim to be different types

Magic bytes detection analyzes the actual file content to determine the true file type, making it much more reliable for security and processing purposes.

Examples

Example 1: Simple File Analysis

Workflow: Manual Trigger → HTTP Request → File Type Detector

alt text

HTTP Request Configuration:

  • URL: https://httpbin.org/image/png
  • Response Format: File

Result: Detects the file as a PNG image with high confidence.

Example 2: Email Attachment Processing

Workflow: Email Trigger → File Type Detector → IF (by category) → Process Accordingly

IF Node Logic:

  • If fileCategory equals "image" → Send to image processing
  • If fileCategory equals "document" → Send to OCR processing
  • Else → Log unknown file type

Example 3: Security Validation

Workflow: Webhook → File Type Detector → IF (confidence check) → Security Action

Security Check:

// In IF node expression
{{ $node["File Type Detector"].json.fileTypeAnalysis.confident === false }}

If confidence is low, flag for manual review.

Development

Want to contribute or modify this node? See DEVELOPMENT.md for local development setup instructions.

Requirements

  • n8n version: 1.0.0 or higher
  • Node.js: 20.19 or higher (for development)

Dependencies

  • file-type: For magic bytes file type detection
  • n8n-workflow: n8n workflow types and interfaces

License

MIT

Support

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.

Changelog

v0.1.0

  • Initial release
  • Magic bytes file type detection
  • File categorization
  • Fallback to original MIME types
  • Comprehensive file analysis output

Made with ❤️ for the n8n community