{"record":{"id":"692bee3685a41770","repo":"jackwener/OpenCLI","slug":"midjourney-media-download-returned-unexpected-cont","errorCode":null,"errorMessage":"Midjourney media download returned unexpected content type \"${payload.type || 'unknown'}\"","messagePattern":"Midjourney media download returned unexpected content type \"(.+?)\"","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":560,"sourceCode":"        const response = await fetch(mediaUrl);\n        if (!response.ok) return { ok: false, status: response.status, type: response.headers.get('content-type') || '' };\n        const bytes = new Uint8Array(await response.arrayBuffer());\n        window[key] = bytes;\n        return {\n          ok: true,\n          status: response.status,\n          type: response.headers.get('content-type') || '',\n          size: bytes.length,\n        };\n      }, url, transferKey));\n    } catch (error) {\n      throw new CommandExecutionError(`Midjourney browser-context media fetch failed: ${errorMessage(error)}`);\n    }\n    if (!payload || typeof payload !== 'object' || !payload.ok) {\n      throw new CommandExecutionError(`Midjourney media download failed: HTTP ${payload?.status ?? 0} from ${url}`);\n    }\n    if (!String(payload.type || '').startsWith(expectedMimePrefix)) {\n      throw new CommandExecutionError(`Midjourney media download returned unexpected content type \"${payload.type || 'unknown'}\"`);\n    }\n    const size = Number(payload.size);\n    if (!Number.isInteger(size) || size <= 0) {\n      throw new CommandExecutionError(`Midjourney media download returned an empty file from ${url}`);\n    }\n\n    // Returning a complete base64 file in one Browser Bridge response can\n    // exceed the daemon message limit. Pull it out in bounded chunks instead.\n    const parts = [];\n    const chunkSize = 96 * 1024;\n    for (let offset = 0; offset < size; offset += chunkSize) {\n      const base64 = unwrapEvaluateResult(await page.evaluate((key, start, length) => {\n        const bytes = window[key];\n        if (!(bytes instanceof Uint8Array)) return null;\n        const chunk = bytes.subarray(start, Math.min(bytes.length, start + length));\n        let binary = '';\n        const binaryChunkSize = 0x8000;\n        for (let index = 0; index < chunk.length; index += binaryChunkSize) {","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L542-L578","documentation":"The media downloaded successfully, but its content-type header does not start with the expected MIME prefix (e.g. expected 'image/' but got 'text/html' or 'application/json'). This usually means the CDN returned an error page or a redirect/interstitial instead of the actual media file.","triggerScenarios":"CDN returns an HTML error page with 200 status; a login/consent interstitial page replaces the media; the URL points to a different resource type than expectedMimePrefix (e.g. expecting video but getting image).","commonSituations":"Expired sessions where the CDN serves an HTML sign-in page; Cloudflare-style challenge pages; passing an image URL where a video was expected.","solutions":["Re-resolve the media URL (the current one is likely serving an interstitial or wrong resource).","Check the reported content type: 'text/html' usually means a challenge/login page; refresh browser session/cookies.","Confirm you are requesting the correct media kind for the job/index.","Retry later if a bot-challenge page is being served."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const res = await fetch(url, { method: 'HEAD' });\nconst ct = res.headers.get('content-type') || '';\nif (!ct.startsWith('image/')) throw new Error('Unexpected content-type ' + ct + '; re-resolve URL');","typeGuard":null,"tryCatchPattern":"try {\n  await downloadMedia(page, url);\n} catch (err) {\n  if (/unexpected content type/.test(err.message)) {\n    const freshUrl = await resolveFreshUrl(jobId); // interstitial/challenge guard\n    await downloadMedia(page, freshUrl);\n  } else throw err;\n}","preventionTips":["Re-resolve URLs when a text/html content type appears (sign of a challenge page).","Keep browser cookies/session valid so CDNs do not serve interstitials.","Verify the expected media kind matches what the job produces.","Route downloads through a clean network path (no injecting proxies)."],"tags":["content-type","validation","cdn","midjourney"],"backgroundTag":"unexpected-content-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}