{"record":{"id":"f1203ec1f0ee5b0b","repo":"jackwener/OpenCLI","slug":"instagram-private-publish-upload-failed-for-prep","errorCode":null,"errorMessage":"Instagram private publish upload failed for ${prepared.asset.fileName}","messagePattern":"Instagram private publish upload failed for (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/private-publish.js","lineNumber":811,"sourceCode":"        }\n        for (const cleanupPath of prepared.asset.cleanupPaths || []) {\n            fs.rmSync(cleanupPath, { force: true });\n        }\n        if (prepared.asset.coverImage.cleanupPath) {\n            fs.rmSync(prepared.asset.coverImage.cleanupPath, { force: true });\n        }\n    }\n}\nasync function uploadPreparedMediaAsset(fetcher, prepared, uploadId, context, mode = 'feed') {\n    if (prepared.type === 'image') {\n        const response = await fetchPrivateUploadWithRetry(fetcher, `https://i.instagram.com/rupload_igphoto/fb_uploader_${uploadId}`, {\n            method: 'POST',\n            headers: buildRuploadHeaders(prepared.asset, uploadId, context),\n            body: prepared.asset.bytes,\n        });\n        const json = await parseJsonResponse(response, 'upload');\n        if (String(json?.status || '') !== 'ok') {\n            throw new CommandExecutionError(`Instagram private publish upload failed for ${prepared.asset.fileName}`);\n        }\n        return;\n    }\n    const videoResponse = await fetchPrivateUploadWithRetry(fetcher, `https://i.instagram.com/rupload_igvideo/fb_uploader_${uploadId}`, {\n        method: 'POST',\n        headers: mode === 'story'\n            ? buildStoryVideoRuploadHeaders(prepared.asset, uploadId, context)\n            : buildVideoRuploadHeaders(prepared.asset, uploadId, context),\n        body: prepared.asset.bytes,\n    });\n    const videoJson = await parseJsonResponse(videoResponse, 'video upload');\n    if (String(videoJson?.status || '') !== 'ok') {\n        throw new CommandExecutionError(`Instagram private publish video upload failed for ${prepared.asset.fileName}`);\n    }\n    const coverResponse = await fetchPrivateUploadWithRetry(fetcher, `https://i.instagram.com/rupload_igphoto/fb_uploader_${uploadId}`, {\n        method: 'POST',\n        headers: buildVideoCoverRuploadHeaders(prepared.asset, uploadId, context),\n        body: prepared.asset.coverImage.bytes,","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/private-publish.js#L793-L829","documentation":"For photo assets, the rupload_igphoto upload response must contain status 'ok'; otherwise this error is thrown at clis/instagram/_shared/private-publish.js:811. The HTTP call and JSON parse succeeded, but Instagram rejected the upload contents or metadata at the application level.","triggerScenarios":"POST to https://i.instagram.com/rupload_igphoto/fb_uploader_<uploadId> returns JSON with status other than 'ok' — e.g. invalid image bytes, wrong Content-Length/rupload headers, media violating policies, or an expired upload session.","commonSituations":"Uploading images with unsupported formats or oversized dimensions; photo bytes truncated before upload; session/entity-id headers stale; account restricted from posting.","solutions":["Inspect the parsed response body for a `message` field explaining why status !== 'ok' (add logging around the upload call if needed)","Re-encode the image to a standard JPEG/PNG within Instagram's dimension limits and retry","Refresh session cookies and restart the publish so a fresh uploadId is generated","Verify the file was fully read (no truncation) before upload"],"exampleFix":"// before\nconst bytes = fs.readFileSync(maybePartialFile);\n// after\nconst stat = fs.statSync(imgPath);\nif (stat.size === 0) throw new Error('image file is empty');\nconst bytes = fs.readFileSync(imgPath);","handlingStrategy":"validation","validationCode":"const stat = fs.statSync(imagePath);\nif (stat.size === 0) throw new Error('image bytes are empty');\nif (stat.size > 8 * 1024 * 1024) throw new Error('image exceeds Instagram upload limits');","typeGuard":null,"tryCatchPattern":"try { await publish(input); }\ncatch (e) {\n  if (/upload failed for/.test(e.message)) {\n    console.error('Instagram rejected the photo upload; check format/dimensions and refresh session');\n  }\n  throw e;\n}","preventionTips":["Convert images to standard JPEG/PNG within Instagram dimension limits","Ensure the full file is read into memory before upload (no truncation)","Re-authenticate when uploads repeatedly fail with non-ok status"],"tags":["instagram-api","upload","http-response","media"],"backgroundTag":"upload-rejected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}