weixin-ts / cdn/src / uploadMedia
Function: uploadMedia()
uploadMedia(
options):Promise<UploadedMedia>
Defined in: cdn/src/upload.ts:81
Upload a media file to the WeChat CDN.
This handles the full upload pipeline:
- Compute file hash (MD5)
- Generate AES-128 key and file key
- Request pre-signed upload URL from the API
- Encrypt file with AES-128-ECB
- Upload encrypted file to CDN
- Return upload info for message construction
Parameters
options
Upload configuration
Returns
Promise<UploadedMedia>
Upload result with CDN parameters for message construction
Example
ts
import { uploadMedia } from '@weixin-ts/cdn'
const result = await uploadMedia({
file: imageBuffer,
toUserId: 'recipient_id',
mediaType: 'image',
apiOptions: { baseUrl: 'https://ilinkai.weixin.qq.com', token: '...' },
cdnBaseUrl: 'https://novac2c.cdn.weixin.qq.com/c2c',
})
// Use result.downloadParam in message construction