npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

n8n-nodes-file-type-detector

v0.2.0

Published

n8n node for detecting file types using magic bytes analysis

Downloads

151

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

Via n8n Community Nodes (Recommended)

  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