yikart/AiToEarn · error · ChannelPlatformException
ChannelPlatformMediaProcessingFailed
ChannelPlatformMediaProcessingFailed
Error message
ChannelPlatformMediaProcessingFailed
What it means
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).
Source
Thrown at project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/wechat/wechat.service.ts:473
publishStatus: response.data.publish_status,
articleId: response.data.article_id,
articleUrl: response.data.article_url,
}
}
async uploadImage(imageBuffer: Buffer, filename: string): Promise<string> {
const accessToken = await this.getOfficialAccessToken()
const formData = new FormData()
formData.append('media', new Blob([new Uint8Array(imageBuffer)]), filename)
const response = await this.httpClient.post<WeChatMediaUploadResponse>(
`https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=${accessToken}`,
formData,
{ headers: { 'Content-Type': 'multipart/form-data' } },
)
if (!response.data.url) {
throw new ChannelPlatformException({
code: ResponseCode.ChannelPlatformMediaProcessingFailed,
platform: AccountType.WeChatOfficial,
category: PlatformErrorCategory.Validation,
context: { endpoint: 'uploadImage' },
cause: {
type: PlatformErrorCauseType.Validation,
platformMessage: 'Missing image url in uploadImage response',
raw: response.data,
},
})
}
return response.data.url
}
async uploadThumbImage(imageBuffer: Buffer, filename: string): Promise<string> {
const accessToken = await this.getOfficialAccessToken()
const formData = new FormData()View on GitHub (pinned to d3aa8bea5b)
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
Example fix
// before
if (!response.data.url) {
throw new ChannelPlatformException({ code: ResponseCode.ChannelPlatformMediaProcessingFailed, ... })
}
// after
if (!response.data.url) {
this.logger.warn(`uploadimg failed, errcode=${response.data?.errcode} errmsg=${response.data?.errmsg}`)
throw new ChannelPlatformException({ code: ResponseCode.ChannelPlatformMediaProcessingFailed, ... })
} Defensive patterns
Strategy: try-catch
Validate before calling
const validateImage = (f: { size: number; mime: string }) => {
if (f.size > 10 * 1024 * 1024) throw new Error('image exceeds WeChat 10MB limit')
if (!['image/jpeg', 'image/png'].includes(f.mime)) throw new Error('WeChat uploadimg accepts JPG/PNG only')
} Type guard
function hasImageUrl(r: unknown): r is { url: string } {
return typeof (r as any)?.url === 'string' && (r as any).url.startsWith('http')
} Try / catch
try {
const { url } = await wechatService.uploadImage(accessToken, file)
} catch (e) {
if (String(e?.message).includes('ChannelPlatformMediaProcessingFailed')) {
const refreshed = await tokenService.getFreshAccessToken(accountId)
return wechatService.uploadImage(refreshed, file) // retry once with fresh token
}
throw e
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No subtitle entries in response
- No response from Gemini
- Invalid subtitle data: ${z.prettifyError(result.error)}
- Canvas not provided and no vid:// video source found in Trac
- Canvas not provided and failed to retrieve video dimensions
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/04fc9c6063fc67b1.
Report an issue: GitHub.