{"record":{"id":"29a8d3b4381a283d","repo":"mastra-ai/mastra","slug":"media-type-is-missing-for-file-part","errorCode":null,"errorMessage":"Media type is missing for file part","messagePattern":"Media type is missing for file part","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/message-list/prompt/convert-file.ts","lineNumber":60,"sourceCode":"      // to deal with incorrect media type inputs.\n      // When detection fails, use provided media type.\n      if (data instanceof Uint8Array || typeof data === 'string') {\n        mediaType = detectMediaType({ data, signatures: imageMediaTypeSignatures }) ?? mediaType;\n      }\n\n      return {\n        type: 'file',\n        mediaType: mediaType ?? 'image/*', // any image\n        filename: undefined,\n        data,\n        providerOptions: part.providerOptions,\n      };\n    }\n\n    case 'file': {\n      // We must have a mediaType for files, if not, throw an error.\n      if (mediaType == null) {\n        throw new Error(`Media type is missing for file part`);\n      }\n\n      return {\n        type: 'file',\n        mediaType,\n        filename: part.filename,\n        data,\n        providerOptions: part.providerOptions,\n      };\n    }\n  }\n}\n","sourceCodeStart":42,"sourceCodeEnd":73,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/message-list/prompt/convert-file.ts#L42-L73","documentation":"Unlike images (which can fall back to 'image/*'), file parts must have a concrete mediaType for the provider request. After conversion/download attempts, if convertImageFilePart still has no mediaType for a 'file' part, it throws 'Media type is missing for file part'.","triggerScenarios":"A FilePart whose data yields no detectable media type (URL not in downloadedAssets or response lacked content-type) and whose part.mediaType / attachment.contentType was never set — e.g. { type: 'file', data: url } with no mimeType anywhere in the chain.","commonSituations":"Downloading assets from servers that omit the Content-Type header; building FileParts manually from raw base64 without mimeType; gs:// or s3:// attachments where contentType was inferred as image only for some files.","solutions":["Set mediaType explicitly on the FilePart (or contentType on the originating attachment).","Serve the asset with a proper Content-Type header so download-assets can capture it.","For URLs, ensure the asset is included in downloadedAssets (run downloadAssets so the header-derived media type is available).","If the data is an image, use an image part or set 'image/png'-style mediaType instead of relying on fallback detection."],"exampleFix":"// before\n{ type: 'file', data: 'https://cdn.example.com/report' }\n// after\n{ type: 'file', data: 'https://cdn.example.com/report', mediaType: 'application/pdf' }","handlingStrategy":"validation","validationCode":"function assertFilePartHasMediaType(part: { type: 'file'; mediaType?: string; data: unknown }) {\n  if (part.type === 'file' && !part.mediaType) {\n    throw new Error('FilePart requires mediaType before prompt conversion');\n  }\n}","typeGuard":"function isTypedFilePart(p: { type: string; mediaType?: string }): p is { type: 'file'; mediaType: string; data: unknown } {\n  return p.type === 'file' && typeof p.mediaType === 'string' && p.mediaType.includes('/');\n}","tryCatchPattern":"try {\n  converted = convertImageFilePart(part, downloadedAssets);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Media type is missing')) {\n    converted = convertImageFilePart({ ...part, mediaType: 'application/octet-stream' }, downloadedAssets);\n  } else throw e;\n}","preventionTips":["Always set mediaType on file parts at construction time.","Serve assets with an explicit Content-Type header so downloads capture it.","Ensure downloadAssets ran for URL parts so the header-derived media type is available."],"tags":["file-part","mime-type","conversion"],"backgroundTag":"missing-media-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}