{"record":{"id":"a93c0cf5f850350c","repo":"yikart/AiToEarn","slug":"channelplatformmediaprocessingfailed","errorCode":"ChannelPlatformMediaProcessingFailed","errorMessage":"ResponseCode.ChannelPlatformMediaProcessingFailed","messagePattern":"ResponseCode\\.ChannelPlatformMediaProcessingFailed","errorType":"exception","errorClass":"AppException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-server/src/core/channels/media/media.service.ts","lineNumber":909,"sourceCode":"  }\n\n  private isImageExtension(extension: string | undefined): boolean {\n    return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff'].includes(extension ?? '')\n  }\n\n  private async downloadBuffer(url: string, input?: MediaHttpInput, maxBytes?: number): Promise<Buffer> {\n    const response = await this.http.get<ArrayBuffer | Buffer>(url, {\n      responseType: 'arraybuffer',\n      maxContentLength: maxBytes ?? Infinity,\n      maxBodyLength: maxBytes ?? Infinity,\n      ...(input ? { channelMedia: input } : {}),\n    })\n    const buffer = Buffer.isBuffer(response.data)\n      ? response.data\n      : Buffer.from(response.data)\n    if (maxBytes && buffer.length > maxBytes) {\n      if (!input) {\n        throw new AppException(ResponseCode.ChannelPlatformMediaProcessingFailed, {\n          reasonCode: 'media_exceeds_max_bytes',\n          maxBytes,\n          sizeBytes: buffer.length,\n        })\n      }\n      throw new ChannelPlatformException({\n        code: ResponseCode.ChannelPlatformMediaProcessingFailed,\n        platform: input.platform,\n        category: PlatformErrorCategory.MediaProcessingFailed,\n        context: {\n          endpoint: input.endpoint,\n          taskId: input.taskId,\n          accountId: input.accountId,\n          platformWorkId: input.platformWorkId,\n        },\n        cause: {\n          type: PlatformErrorCauseType.Platform,\n          platformMessage: 'Media exceeds maximum byte size',","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-server/src/core/channels/media/media.service.ts#L891-L927","documentation":"When downloading media without a platform/endpoint context (`input` is null), MediaService enforces a max byte size. If the downloaded buffer exceeds maxBytes it throws AppException ChannelPlatformMediaProcessingFailed with reasonCode 'media_exceeds_max_bytes' instead of the platform-scoped ChannelPlatformException.","triggerScenarios":"A media fetch/download produced a buffer larger than maxBytes while input was null (no platform context supplied), so the guard at the `if (!input)` branch fires.","commonSituations":"Downloading an oversized video/image from a URL with a size cap configured; user supplies a very large media file link; maxBytes configured conservatively (e.g. platform upload limits) and remote asset grew.","solutions":["Check the returned context: sizeBytes vs maxBytes; source smaller media or re-encode/compress before upload.","Raise maxBytes in the call site if the destination platform actually allows larger files.","Provide platform/endpoint context (`input`) so the more informative ChannelPlatformException with platform/category is thrown instead.","Catch this code and surface a 'file too large' message with both sizes."],"exampleFix":"// before\nawait media.download(url, { maxBytes: 8 * 1024 * 1024 })\n\n// after\nawait media.download(url, { maxBytes: 512 * 1024 * 1024 }) // match platform limit","handlingStrategy":"validation","validationCode":"const head = await axios.head(mediaUrl)\nconst size = Number(head.headers['content-length'] ?? 0)\nif (size > maxBytes) throw new Error(`Media ${size} bytes exceeds limit ${maxBytes}`)","typeGuard":null,"tryCatchPattern":"try {\n  await media.fetch(url, { maxBytes })\n} catch (e) {\n  if (e.code === 'ChannelPlatformMediaProcessingFailed' && e.context?.reasonCode === 'media_exceeds_max_bytes') {\n    return { error: 'FILE_TOO_LARGE', maxBytes: e.context.maxBytes, sizeBytes: e.context.sizeBytes }\n  }\n  throw e\n}","preventionTips":["Set maxBytes to match the destination platform's real upload limit","HEAD-check content-length before downloading large media","Compress/re-encode oversized media server-side before fetching"],"tags":["media","file-size","limit-exceeded"],"backgroundTag":"media-size-limit-exceeded","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}