wavetermdev/waveterm · error
file part missing mimetype
Error message
file part missing mimetype
What it means
A file-type message part reached convertFileAIMessagePart without a MimeType. The converter needs the mimetype to route the part to image, PDF, text, or directory handling, so a missing one is rejected outright. This is an input validation error, not a network error.
Source
Thrown at pkg/aiusechat/openai/openai-convertmessage.go:329
}
if chatOpts.ChatId != "" {
req.Header.Set("X-Wave-ChatId", chatOpts.ChatId)
}
req.Header.Set("X-Wave-Version", wavebase.WaveVersion)
req.Header.Set("X-Wave-APIType", uctypes.APIType_OpenAIResponses)
req.Header.Set("X-Wave-RequestType", chatOpts.GetWaveRequestType())
}
return req, nil
}
// convertFileAIMessagePart converts a file AIMessagePart to OpenAI format
func convertFileAIMessagePart(part uctypes.AIMessagePart) (*OpenAIMessageContent, error) {
if part.Type != uctypes.AIMessagePartTypeFile {
return nil, fmt.Errorf("convertFileAIMessagePart expects 'file' type, got '%s'", part.Type)
}
if part.MimeType == "" {
return nil, fmt.Errorf("file part missing mimetype")
}
// Handle different file types
switch {
case strings.HasPrefix(part.MimeType, "image/"):
imageUrl, err := aiutil.ExtractImageUrl(part.Data, part.URL, part.MimeType)
if err != nil {
return nil, err
}
return &OpenAIMessageContent{
Type: "input_image",
ImageUrl: imageUrl,
Filename: part.FileName,
PreviewUrl: part.PreviewUrl,
}, nil
case part.MimeType == "application/pdf":View on GitHub (pinned to a4447c1563)
Solutions
- Set part.MimeType explicitly (e.g. "image/png", "application/pdf", "text/plain") before sending the message
- Use http.DetectContentType on the file bytes to infer the mimetype when unknown
- Validate message parts (type + mimetype + data/url present) before calling the chat API
Example fix
// before
part := uctypes.AIMessagePart{Type: uctypes.AIMessagePartTypeFile, FileName: "report.pdf"}
// after
part := uctypes.AIMessagePart{Type: uctypes.AIMessagePartTypeFile, FileName: "report.pdf", MimeType: "application/pdf", Data: pdfBytes} Defensive patterns
Strategy: validation
Validate before calling
if part.Type == uctypes.AIMessagePartTypeFile && part.MimeType == "" {
part.MimeType = http.DetectContentType(part.Data) // infer from bytes
}
if part.MimeType == "" { return errors.New("file part missing mimetype") } Type guard
func hasMimetype(p uctypes.AIMessagePart) bool {
return p.Type == uctypes.AIMessagePartTypeFile && p.MimeType != ""
} Prevention
- Set MimeType at part construction from upload metadata
- Use http.DetectContentType as fallback for unknown files
- Validate all parts in one pre-send pass
When it happens
Trigger: Adding an AIMessagePart with Type 'file' but leaving MimeType empty (e.g. attached a file from disk without detecting its content type); APIs/paths that build parts from user upload metadata lacking a content-type header.
Common situations: Attachments uploaded through custom frontends that don't set MIME types; files with unrecognized extensions where mime detection returned empty; copying part-construction code and omitting MimeType.
Related errors
- convertFileAIMessagePart expects 'file' type, got '%s'
- invalid AIMessage: %w
- file part missing url
- file part missing mediaType
- invalid data URL format
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/efeb8a62ccfba654.
Report an issue: GitHub.