Skip to content

fix(Google Gemini Node): Determine the file extention from MIME type for image and video operations#28616

Merged
RomanDavydchuk merged 3 commits intomasterfrom
node-4708
Apr 20, 2026
Merged

fix(Google Gemini Node): Determine the file extention from MIME type for image and video operations#28616
RomanDavydchuk merged 3 commits intomasterfrom
node-4708

Conversation

@RomanDavydchuk
Copy link
Copy Markdown
Contributor

Summary

Google Gemini node currently always uses png as the file extension for images that are generated/edited and mp4 for generated videos. This causes issues when the actual image/video is not png or mp4. This PR fixes that by determining the file extension based on the file's MIME type

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/NODE-4708/community-issue-google-gemini-node-mismatch-between-mimetype-imagejpeg
Closes #27382

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

@RomanDavydchuk RomanDavydchuk marked this pull request as ready for review April 17, 2026 12:35
@Joffcom Joffcom requested a review from dlavrenuek April 17, 2026 12:36
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

Performance Comparison

Comparing currentlatest master14-day baseline

Idle baseline with Instance AI module loaded

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
instance-ai-heap-used-baseline 186.29 MB 186.29 MB 186.40 MB (σ 0.27) +0.0% -0.1%
instance-ai-rss-baseline 342.32 MB 342.32 MB 362.79 MB (σ 23.42) +0.0% -5.6%

docker-stats

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
docker-image-size-runners 386.00 MB 386.00 MB 391.20 MB (σ 9.93) +0.0% -1.3%
docker-image-size-n8n 1269.76 MB 1269.76 MB 1269.76 MB (σ 0.00) +0.0% +0.0%

Memory consumption baseline with starter plan resources

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
memory-heap-used-baseline 114.77 MB 114.54 MB 114.20 MB (σ 0.47) +0.2% +0.5% ⚠️
memory-rss-baseline 290.41 MB 332.36 MB 290.22 MB (σ 47.80) -12.6% +0.1%
How to read this table
  • Current: This PR's value (or latest master if PR perf tests haven't run)
  • Latest Master: Most recent nightly master measurement
  • Baseline: Rolling 14-day average from master
  • vs Master: PR impact (current vs latest master)
  • vs Baseline: Drift from baseline (current vs rolling avg)
  • Status: ✅ within 1σ | ⚠️ 1-2σ | 🔴 >2σ regression

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

Architecture diagram
sequenceDiagram
    participant E as n8n Execution Engine
    participant G as Google Gemini Node
    participant U as Helper Utils
    participant API as Google Gemini API
    participant EXT as External Storage (URL)

    Note over E, EXT: Image/Video Generation & Processing Flow

    E->>G: execute()
    
    alt Image Generation / Editing
        G->>API: POST /v1beta/models/...:generateContent
        API-->>G: Returns base64 data + mimeType
    else Video Generation (Asynchronous)
        G->>API: POST /v1beta/models/...:generateVideo
        API-->>G: Returns Operation URI
        loop Poll Status
            G->>API: GET Operation Status
            API-->>G: done: true + video uri
        end
        G->>EXT: Download video from URI
        EXT-->>G: Returns Buffer + mimeType
    else Video Download (Direct)
        G->>EXT: Download video from provided URL
        EXT-->>G: Returns Buffer + mimeType
    end

    Note over G, U: NEW: Extension Resolution Logic
    G->>U: NEW: getFilenameFromMimeType(mimeType, baseName, fallback)
    U->>U: Lookup extension using 'mime-types' library
    
    alt MIME type recognized
        U-->>G: Returns e.g., "image.jpg" or "video.webm"
    else MIME type unknown/missing
        U-->>G: Returns fallback (e.g., "image.png" or "video.mp4")
    end

    G->>G: CHANGED: prepareBinaryData(buffer, fileName, mimeType)
    Note right of G: Previously hardcoded to .png or .mp4
    
    G-->>E: Return NodeExecutionData (Binary + JSON)
Loading

@RomanDavydchuk RomanDavydchuk added this pull request to the merge queue Apr 20, 2026
Merged via the queue into master with commit 73659cb Apr 20, 2026
59 checks passed
@RomanDavydchuk RomanDavydchuk deleted the node-4708 branch April 20, 2026 08:33
@n8n-assistant n8n-assistant Bot mentioned this pull request Apr 21, 2026
@n8n-assistant
Copy link
Copy Markdown
Contributor

n8n-assistant Bot commented Apr 21, 2026

Got released with n8n@2.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google Gemini Node: Mismatch between mimeType (image/jpeg) and fileExtension (png)

2 participants