{"record":{"id":"192ea6801e1a9f19","repo":"jackwener/OpenCLI","slug":"midjourney-cdn-reported-media-mime-unknown-192ea6","errorCode":null,"errorMessage":"Midjourney CDN reported ${media.mime || 'unknown'} for ${url}; detected ${actualMime} from file bytes","messagePattern":"Midjourney CDN reported (.+?) for (.+?); detected (.+?) from file bytes","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"clis/midjourney/utils.js","lineNumber":723,"sourceCode":"  } catch (error) {\n    await fs.unlink(tempPath).catch(() => {});\n    throw new CommandExecutionError(`Could not write Midjourney media ${filePath}: ${errorMessage(error)}`);\n  }\n}\n\nexport async function downloadRawVideo(page, jobId, index, outputDir, force = false) {\n  await fs.mkdir(outputDir, { recursive: true });\n  const url = rawVideoUrl(jobId, index);\n  const filePath = path.join(outputDir, `${jobId}_${index + 1}_raw.mp4`);\n  const existing = await existingMedia(filePath, force, 'video/mp4');\n  if (existing) return { index, kind: 'video-raw', filePath, bytes: existing.size, url, mime: 'video/mp4', cached: true };\n  const media = await fetchMediaThroughPage(page, url, 'video/');\n  const actualMime = sniffMediaMime(media.buffer);\n  if (actualMime !== 'video/mp4') {\n    throw new CommandExecutionError(`Midjourney raw video returned invalid MP4 bytes from ${url}`);\n  }\n  if (media.mime !== actualMime) {\n    log.warn(`Midjourney CDN reported ${media.mime || 'unknown'} for ${url}; detected ${actualMime} from file bytes`);\n  }\n  await writeMediaBuffer(filePath, media.buffer);\n  return { index, kind: 'video-raw', filePath, bytes: media.buffer.length, url, mime: actualMime, cached: false };\n}\n\nexport async function downloadRenderedVideo(page, jobId, index, kind, outputDir, force = false) {\n  const config = kind === 'video-social'\n    ? { label: 'Download for Social', extension: '.mp4', mime: 'video/mp4' }\n    : kind === 'gif'\n      ? { label: 'Download as GIF', extension: '.gif', mime: 'image/gif' }\n      : null;\n  if (!config) throw new ArgumentError('Rendered video kind must be video-social or gif');\n  await fs.mkdir(outputDir, { recursive: true });\n  const filePath = path.join(outputDir, `${jobId}_${index + 1}_${kind.replace('video-', '')}${config.extension}`);\n  const existing = await existingMedia(filePath, force, config.mime);\n  if (existing) return { index, kind, filePath, bytes: existing.size, url: null, mime: config.mime, cached: true };\n\n  await page.goto(jobUrl(jobId, index));","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L705-L741","documentation":"When downloading a raw Midjourney video, the CDN-reported Content-Type disagreed with the MP4 type detected from the file bytes. The bytes were validated as video/mp4 (otherwise it would throw), so this is only a warning before the buffer is written to disk.","triggerScenarios":"fetchMediaThroughPage retrieves a raw video URL and media.mime (response header) differs from sniffMediaMime(buffer) which returned video/mp4.","commonSituations":"CDN serving videos with application/octet-stream or wrong Content-Type, browser-bridge page fetch reporting a generic MIME, CDN transcode/edge-cache misconfiguration.","solutions":["No action required if the saved .mp4 plays correctly — bytes were validated as MP4","Verify the output file with a media probe (ffprobe) if in doubt","Check for proxies altering response headers","Report persistent mismatches for a specific URL/region to the library maintainers"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const actual = sniffMediaMime(buffer);\nif (actual !== 'video/mp4') throw new Error(`Expected video/mp4, got ${actual}`);","typeGuard":"const isMp4 = (m) => m === 'video/mp4';","tryCatchPattern":"try {\n  await downloadRawVideo(page, jobId, index);\n} catch (err) {\n  if (/invalid MP4 bytes/.test(err.message)) { /* retry or fetch alternate rendition */ }\n}","preventionTips":["Validate the sniffed MIME (video/mp4) before persisting files","Play/probe output .mp4 files after batch downloads","Route downloads around header-rewriting proxies/CDNs","Log header-vs-sniff mismatches to spot persistently mislabeled CDN paths"],"tags":["mime-mismatch","video","midjourney","cdn"],"backgroundTag":"content-type-mismatch","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}