{"record":{"id":"04fc9c6063fc67b1","repo":"yikart/AiToEarn","slug":"channelplatformmediaprocessingfailed-04fc9c","errorCode":"ChannelPlatformMediaProcessingFailed","errorMessage":"ChannelPlatformMediaProcessingFailed","messagePattern":"ChannelPlatformMediaProcessingFailed","errorType":"error_code","errorClass":"ChannelPlatformException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/wechat/wechat.service.ts","lineNumber":473,"sourceCode":"      publishStatus: response.data.publish_status,\n      articleId: response.data.article_id,\n      articleUrl: response.data.article_url,\n    }\n  }\n\n  async uploadImage(imageBuffer: Buffer, filename: string): Promise<string> {\n    const accessToken = await this.getOfficialAccessToken()\n    const formData = new FormData()\n    formData.append('media', new Blob([new Uint8Array(imageBuffer)]), filename)\n\n    const response = await this.httpClient.post<WeChatMediaUploadResponse>(\n      `https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=${accessToken}`,\n      formData,\n      { headers: { 'Content-Type': 'multipart/form-data' } },\n    )\n\n    if (!response.data.url) {\n      throw new ChannelPlatformException({\n        code: ResponseCode.ChannelPlatformMediaProcessingFailed,\n        platform: AccountType.WeChatOfficial,\n        category: PlatformErrorCategory.Validation,\n        context: { endpoint: 'uploadImage' },\n        cause: {\n          type: PlatformErrorCauseType.Validation,\n          platformMessage: 'Missing image url in uploadImage response',\n          raw: response.data,\n        },\n      })\n    }\n\n    return response.data.url\n  }\n\n  async uploadThumbImage(imageBuffer: Buffer, filename: string): Promise<string> {\n    const accessToken = await this.getOfficialAccessToken()\n    const formData = new FormData()","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/wechat/wechat.service.ts#L455-L491","documentation":"uploadImage posts media to WeChat's /cgi-bin/media/uploadimg endpoint and expects a response containing a url for the uploaded image. When response.data.url is missing, ChannelPlatformException with code ChannelPlatformMediaProcessingFailed and category Validation is thrown, indicating WeChat did not return a usable image URL (typically an errcode/error response).","triggerScenarios":"Uploading an image over 10MB, unsupported format, invalid/expired access_token causing an errcode in the body (with no url), or network truncation producing an empty response body.","commonSituations":"Expired Official Account access token, oversized or non-JPEG/PNG images, WeChat API returning {errcode:40001,...} that the code surfaces as a media-processing failure.","solutions":["Log response.data fully to read WeChat's errcode/errmsg and act on the real cause","Refresh the access token if errcode indicates 40001/42001 (invalid/expired token)","Validate image size (<10MB) and format (JPG/PNG) before calling uploadImage","Retry the upload on transient network errors"],"exampleFix":"// before\nif (!response.data.url) {\n  throw new ChannelPlatformException({ code: ResponseCode.ChannelPlatformMediaProcessingFailed, ... })\n}\n// after\nif (!response.data.url) {\n  this.logger.warn(`uploadimg failed, errcode=${response.data?.errcode} errmsg=${response.data?.errmsg}`)\n  throw new ChannelPlatformException({ code: ResponseCode.ChannelPlatformMediaProcessingFailed, ... })\n}","handlingStrategy":"try-catch","validationCode":"const validateImage = (f: { size: number; mime: string }) => {\n  if (f.size > 10 * 1024 * 1024) throw new Error('image exceeds WeChat 10MB limit')\n  if (!['image/jpeg', 'image/png'].includes(f.mime)) throw new Error('WeChat uploadimg accepts JPG/PNG only')\n}","typeGuard":"function hasImageUrl(r: unknown): r is { url: string } {\n  return typeof (r as any)?.url === 'string' && (r as any).url.startsWith('http')\n}","tryCatchPattern":"try {\n  const { url } = await wechatService.uploadImage(accessToken, file)\n} catch (e) {\n  if (String(e?.message).includes('ChannelPlatformMediaProcessingFailed')) {\n    const refreshed = await tokenService.getFreshAccessToken(accountId)\n    return wechatService.uploadImage(refreshed, file) // retry once with fresh token\n  }\n  throw e\n}","preventionTips":["Refresh access tokens proactively (WeChat errcode 40001/42001)","Enforce 10MB / JPG+PNG limits client-side","Log errcode/errmsg from uploadimg responses","Retry transient network failures with backoff"],"tags":["wechat","media-upload","image","validation","access-token"],"backgroundTag":"media-processing-failed","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}