{"record":{"id":"bac3d36b07ffc6f0","repo":"gitroomhq/postiz-app","slug":"could-not-determine-the-media-size-for-upload-bac3d3","errorCode":null,"errorMessage":"Could not determine the media size for upload","messagePattern":"Could not determine the media size for upload","errorType":"exception","errorClass":"BadBody","httpStatus":null,"severity":"error","filePath":"libraries/nestjs-libraries/src/integrations/social/whop.provider.ts","lineNumber":247,"sourceCode":"    const attachments: { id: string }[] = [];\n\n    for (const item of media) {\n      // The size comes from a HEAD request; the PUT below streams the bytes\n      // so the file is never buffered in memory (it used to stay resident\n      // through the whole ~9 minute status poll).\n      const headResponse = await fetch(item.path, {\n        method: 'HEAD',\n        // identity encoding so content-length matches the bytes the GET streams\n        headers: { 'accept-encoding': 'identity' },\n        // @ts-ignore - undici-only option; blocks SSRF to internal IPs\n        dispatcher: getSsrfSafeDispatcher(),\n      });\n      const contentLength = Number(\n        headResponse.headers.get('content-length') || 0\n      );\n      if (!headResponse.ok || !contentLength) {\n        // A permanent condition - fail fast instead of letting Temporal retry\n        throw new BadBody(\n          this.identifier,\n          '{}',\n          '{}',\n          'Could not determine the media size for upload'\n        );\n      }\n      const fileName = item.path.split('/').pop() || 'file';\n\n      const createFileResponse = await (\n        await this.fetch(\n          'https://api.whop.com/api/v1/files',\n          {\n            method: 'POST',\n            headers: {\n              Authorization: `Bearer ${accessToken}`,\n              'Content-Type': 'application/json',\n            },\n            body: JSON.stringify({","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts#L229-L265","documentation":"uploadMediaToWhop does a HEAD request to determine the media's content-length; if the HEAD fails or returns no content-length it throws BadBody 'Could not determine the media size for upload' as a permanent (non-retryable) condition.","triggerScenarios":"HEAD on the media URL returns non-2xx (expired presigned URL, 403, 404) or lacks a Content-Length header (chunked/compressed encoding, or storage that refuses HEAD).","commonSituations":"Media stored behind services that don't answer HEAD (some CDns/serverless stores); presigned URL expired before the upload ran; media deleted from the library while the post was pending.","solutions":["curl -I the media URL and confirm a 200 with a Content-Length header","Re-upload the media to get a fresh URL, then retry the post","If your storage doesn't support HEAD, serve media from one that does (S3/compatible)","Ensure nothing strips Content-Length (e.g. on-the-fly gzip) for HEAD requests"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const head = await fetch(mediaUrl, { method: 'HEAD' });\nif (!head.ok || !Number(head.headers.get('content-length'))) { /* re-upload media or block the post before calling uploadMediaToWhop */ }","typeGuard":"const hasKnownSize = (h: Headers) => h.get('content-length') !== null && Number(h.headers?.['content-length']) > 0;","tryCatchPattern":"catch (e) { if (e instanceof BadBody && e.message.includes('media size')) { /* permanent: re-add media, do not retry */ } throw e; }","preventionTips":["Serve media from storage that answers HEAD with Content-Length","Ensure presigned URLs are fresh when the post executes","Don't compress media responses dynamically (kills Content-Length)"],"tags":["whop","media-upload","head-request","content-length"],"backgroundTag":"media-url-unfetchable","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}