upload
Upload media to WhatsApp’s CDN with automatic encryption.Raw media bytes to upload. The data is automatically encrypted using AES-256-CBC before uploading.
Type of media being uploaded. Determines the CDN endpoint and encryption keys:
MediaType::Image- Images and stickersMediaType::Video- Video filesMediaType::Audio- Audio files and voice notesMediaType::Document- Documents and other filesMediaType::Sticker- Sticker imagesMediaType::LinkThumbnail- Link preview thumbnails
Contains all metadata needed to include the media in a message:
Full CDN URL where the encrypted file was uploaded
CDN path component (e.g.,
/v/t62.7118-24/12345_67890). Used for downloads.32-byte encryption key. Required for the recipient to decrypt the media.
SHA-256 hash of the encrypted file. Used for integrity verification during download.
SHA-256 hash of the original (decrypted) file. Used for final validation after decryption.
Original file size in bytes (before encryption)
Example: Upload and Send Image
Example: Upload Video with Progress
Example: Upload Document
Example: Upload Audio (Voice Note)
Media Encryption
All media uploaded to WhatsApp is end-to-end encrypted before transmission:Encryption Process
- Generate keys: Create random 32-byte
media_key - Derive keys: Use HKDF-SHA256 with media type info string to derive:
- 16-byte IV (initialization vector)
- 32-byte cipher key
- 32-byte MAC key
- Encrypt: Apply AES-256-CBC with PKCS7 padding
- Compute MAC: HMAC-SHA256 over IV + ciphertext, append first 10 bytes
- Upload: POST encrypted bytes to WhatsApp CDN
- Return metadata:
media_key, hashes, and CDN path for message
Key Derivation
Each media type uses a specific HKDF info string:media_key is shared with recipients through the encrypted message, allowing them to decrypt the media.
Encryption vs Decryption
The encryption process is the inverse of download decryption:| Upload (Encryption) | Download (Decryption) |
|---|---|
Generate media_key | Receive media_key in message |
| Derive IV, cipher key, MAC key | Derive same keys from media_key |
| Encrypt with AES-256-CBC | Decrypt with AES-256-CBC |
| Append HMAC-SHA256 (10 bytes) | Verify HMAC-SHA256 |
| Upload to CDN | Download from CDN |
MediaType
Specifies the type of media for encryption and CDN routing.JPEG, PNG, or other image formats. Uses
"image" MMS endpoint and "WhatsApp Image Keys" for HKDF.MP4 or other video formats. Uses
"video" MMS endpoint and "WhatsApp Video Keys" for HKDF.Audio files and voice notes. Uses
"audio" MMS endpoint and "WhatsApp Audio Keys" for HKDF.PDF, DOCX, ZIP, and other document formats. Uses
"document" MMS endpoint and "WhatsApp Document Keys" for HKDF.Sticker images (WebP format). Uses
"image" MMS endpoint and "WhatsApp Image Keys" for HKDF (same as images).History sync data. Uses
"md-msg-hist" MMS endpoint and "WhatsApp History Keys" for HKDF.App state sync data. Uses
"md-app-state" MMS endpoint and "WhatsApp App State Keys" for HKDF.Sticker pack metadata. Uses
"sticker-pack" MMS endpoint.Link preview thumbnails. Uses
"thumbnail-link" MMS endpoint.Upload Endpoint
The upload endpoint is constructed as:{media_host}- CDN hostname from media connection{mms_type}- Media type endpoint (e.g.,"image","video","document"){token}- Base64url-encodedfile_enc_sha256{auth}- Media connection auth token
- Method:
POST - Content-Type:
application/octet-stream - Origin:
https://web.whatsapp.com - Body: Encrypted media bytes
The upload automatically handles media connection refresh. If the connection is expired, it’s renewed before uploading.
Error Handling
Common Upload Errors
CDN returned error status. The response body may contain error details.
Media connection has no available CDN hosts.
Failed to encrypt media (rare, usually indicates invalid input).