FlowiseAI/Flowise · error · Error

Invalid media content

Error message

Invalid media content

What it means

Thrown by messageContentMedia() (line 99) when a content block of type 'media' matches neither the inline-data shape ({mimeType, data}) nor the file-data shape ({mimeType, fileUri}). This is Flowise's fallback media-to-Gemini-Part mapper used when content.type === 'media'. Any media block missing the required keys is rejected rather than silently dropped.

Source

Thrown at packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts:99

function messageContentMedia(content: MessageContentComplex): Part {
    if ('mimeType' in content && 'data' in content) {
        return {
            inlineData: {
                mimeType: content.mimeType as string,
                data: content.data as string
            }
        }
    }
    if ('mimeType' in content && 'fileUri' in content) {
        return {
            fileData: {
                mimeType: content.mimeType as string,
                fileUri: content.fileUri as string
            }
        }
    }
    throw new Error('Invalid media content')
}

function inferToolNameFromPreviousMessages(message: any, previousMessages: BaseMessage[]): string | undefined {
    return previousMessages
        .map((msg) => {
            if (AIMessage.isInstance(msg)) {
                return msg.tool_calls ?? []
            }
            return []
        })
        .flat()
        .find((toolCall) => {
            return toolCall.id === message.tool_call_id
        })?.name
}

function _getStandardContentBlockConverter(isMultimodalModel: boolean) {
    const standardContentBlockConverter: StandardContentBlockConverter<{

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Ensure each media content block contains either { type:'media', mimeType, data } (inline base64) or { type:'media', mimeType, fileUri } (remote file).
  2. If you only have a URL, use the image_url content type instead so it is routed through the URL parser.
  3. Validate the media block shape in the producing node/tool before sending it to the Gemini node.

Example fix

// before (throws): { type: 'media', url: 'https://example.com/img.png' }
// after:           { type: 'media', mimeType: 'image/png', fileUri: 'https://example.com/img.png' }
Defensive patterns

Strategy: validation

Validate before calling

function isValidMedia(c: Record<string, unknown>): boolean {
  const hasInline = typeof c.mimeType === 'string' && typeof c.data === 'string'
  const hasFile = typeof c.mimeType === 'string' && typeof c.fileUri === 'string'
  return hasInline || hasFile
}
for (const part of contentParts) {
  if (part?.type === 'media' && !isValidMedia(part)) {
    throw new Error('media block must contain {mimeType,data} or {mimeType,fileUri}')
  }
}

Type guard

type MediaPart =
  | { type: 'media'; mimeType: string; data: string }
  | { type: 'media'; mimeType: string; fileUri: string }
function isMediaPart(c: unknown): c is MediaPart {
  if (typeof c !== 'object' || c === null || (c as any).type !== 'media') return false
  const o = c as Record<string, unknown>
  return (typeof o.mimeType === 'string' && typeof o.data === 'string')
      || (typeof o.mimeType === 'string' && typeof o.fileUri === 'string')
}

Try / catch

try {
  return convertMessageContentToParts(message, isMultimodal, prev)
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid media content') {
    // log the offending media block and skip or repair it
  }
  throw e
}

Prevention

When it happens

Trigger: A MessageContentComplex block with type 'media' is passed that lacks both the mimeType+data pair and the mimeType+fileUri pair.

Common situations: An upstream node emits a partial media object (e.g., only a url without mimeType), a custom tool returns malformed media content, or a content schema changed between library versions.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/f549a3b2362acb4f. Report an issue: GitHub.