bevyengine/bevy · error · GltfError

invalid image mime type: {0}

Error message

invalid image mime type: {0}

What it means

Variant for an image whose declared MIME type is not a recognized image format. Note the #[from(ignore)] attribute: in this codebase GltfError::InvalidImageMimeType is declared (loader/mod.rs:110) but never constructed — the equivalent failure now occurs inside Image::from_buffer (crates/bevy_image/src/image.rs:2334 raises TextureError::InvalidImageMimeType) and reaches callers wrapped as GltfError::ImageError(TextureError) via mod.rs:112. Match ImageError and inspect its TextureError payload; that is where an unknown image MIME actually surfaces today.

Source

Thrown at crates/bevy_gltf/src/loader/mod.rs:108

        mode: Mode,
    },
    /// Invalid glTF file.
    #[error("invalid glTF file: {0}")]
    Gltf(#[from] gltf::Error),
    /// Binary blob is missing.
    #[error("binary blob is missing")]
    MissingBlob,
    /// Decoding the base64 mesh data failed.
    #[error("failed to decode base64 mesh data")]
    Base64Decode(#[from] base64::DecodeError),
    /// Unsupported buffer format.
    #[error("unsupported buffer format")]
    BufferFormatUnsupported,
    /// The buffer URI was unable to be resolved with respect to the asset path.
    #[error("invalid buffer uri: {0}. asset path error={1}")]
    InvalidBufferUri(String, ParseAssetPathError),
    /// Invalid image mime type.
    #[error("invalid image mime type: {0}")]
    #[from(ignore)]
    InvalidImageMimeType(String),
    /// Error when loading a texture. Might be due to a disabled image file format feature.
    #[error("You may need to add the feature for the file format: {0}")]
    ImageError(#[from] TextureError),
    /// The image URI was unable to be resolved with respect to the asset path.
    #[error("invalid image uri: {0}. asset path error={1}")]
    InvalidImageUri(String, ParseAssetPathError),
    /// Failed to read bytes from an asset path.
    #[error("failed to read bytes from an asset path: {0}")]
    ReadAssetBytesError(#[from] ReadAssetBytesError),
    /// Failed to load asset from an asset path.
    #[error("failed to load asset from an asset path: {0}")]
    AssetLoadError(#[from] AssetLoadError),
    /// Missing sampler for an animation.
    #[error("Missing sampler for animation {0}")]
    #[from(ignore)]
    MissingAnimationSampler(usize),

View on GitHub (pinned to 396ca72708)

Solutions

  1. Re-encode textures to a format Bevy supports (png, jpeg, webp, ktx2/basis, hdr, ...) with a matching MIME.
  2. Match the mime string in JSON to the actual encoded bytes.
  3. When handling the error, match GltfError::ImageError and read the TextureError to see whether it is truly an invalid mime or a disabled cargo feature.
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN: [&str; 6] = ["image/png", "image/jpeg", "image/webp", "image/vnd.khronos.ktx2", "image/ktx2", "image/vnd.khronos.astc"];
fn image_mimes_ok(json: &serde_json::Value) -> bool {
    json["images"].as_array().unwrap_or(&vec![]).iter()
        .filter_map(|i| i["mimeType"].as_str())
        .all(|m| KNOWN.contains(&m))
}

Try / catch

match err {
    // note: GltfError::InvalidImageMimeType is declared but unused;
    // unknown mimes arrive via TextureError inside ImageError
    GltfError::ImageError(TextureError::InvalidImageMimeType(mime)) => {
        error!("unsupported image mime {mime}; re-encode texture");
    }
    other => return Err(other.into()),
}

Prevention

When it happens

Trigger: Historically: an embedded image (Source::View) or data-URI image whose mime_type string was not one of the known image formats. Currently: same input, but reported as ImageError(TextureError::InvalidImageMimeType(mime)) from the Image::from_buffer calls at mod.rs:1228/1250.

Common situations: Exporters writing vendor MIME types for textures; JSON edited to a wrong mime; extension/mime mismatch after renaming texture files.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/4faa70ce1bda8666. Report an issue: GitHub.