download
Download and decrypt media from a message.Any message type that implements the
Downloadable trait. Includes:ImageMessageVideoMessageAudioMessageDocumentMessageStickerMessageExternalBlobReference(app state)HistorySyncNotification
Decrypted media bytes. For encrypted media (E2EE), automatically decrypts using AES-256-CBC and verifies HMAC-SHA256. For plaintext media (newsletters/channels), validates SHA-256 hash.
Example: Download Image
Example: Download with Error Handling
download_to_file
Download media and write directly to a file.Message containing downloadable media
Writer to output the decrypted data. Typically a
File or BufWriter<File>.Example: Download to File
download_to_writer
Download media using streaming (constant memory usage). The entire HTTP download, decryption, and file write happen in a single blocking thread. Memory usage is ~40KB regardless of file size.Message containing downloadable media
Writer for streaming output. Must be Send + ‘static for use in blocking task.
Returns the writer after successful download, seeked back to position 0.
Example: Streaming Download
Use
download_to_writer for large media files to avoid loading entire files into memory. Memory usage is constant ~40KB (8KB read buffer + decryption state).download_from_params
Download and decrypt media from raw parameters without the original message.WhatsApp CDN path (e.g.,
/v/t62.7118-24/12345_67890)32-byte media encryption key from message
SHA-256 hash of decrypted file
SHA-256 hash of encrypted file
Original file size in bytes
Type of media:
Image, Video, Audio, Document, Sticker, etc.Decrypted media bytes
Example: Download from Stored Metadata
download_from_params_to_writer
Streaming variant ofdownload_from_params that writes to a writer.
WhatsApp CDN path
32-byte media encryption key
SHA-256 hash of decrypted file
SHA-256 hash of encrypted file
Original file size in bytes
Type of media
Writer for streaming output
Returns the writer after successful download
Downloadable Trait
TheDownloadable trait provides a generic interface for downloading media from any message type.
WhatsApp CDN path for the media file
32-byte encryption key. Present for E2EE media,
None for plaintext (newsletter/channel) media.SHA-256 hash of the encrypted file. Used for encrypted media validation.
SHA-256 hash of the decrypted file. Used for plaintext media validation.
Original file size in bytes
Media type for HKDF key derivation (
Image, Video, Audio, Document, etc.)Static CDN URL for direct download. Present on newsletter/channel media, bypasses host construction.
Returns
true if media is encrypted (has media_key), false for plaintext mediaBuilt-in Implementations
TheDownloadable trait is automatically implemented for:
wa::message::ImageMessagewa::message::VideoMessagewa::message::AudioMessagewa::message::DocumentMessagewa::message::StickerMessagewa::ExternalBlobReference(app state)wa::message::HistorySyncNotification
MediaType
Media type enum for encryption/decryption.Image/Sticker→"WhatsApp Image Keys"Video→"WhatsApp Video Keys"Audio→"WhatsApp Audio Keys"Document→"WhatsApp Document Keys"History→"WhatsApp History Keys"AppState→"WhatsApp App State Keys"
Media Decryption
WhatsApp uses different handling for encrypted (E2EE) and plaintext media:Encrypted Media (E2EE)
- Download encrypted bytes from CDN
- Verify HMAC-SHA256 (last 10 bytes)
- Decrypt using AES-256-CBC with keys derived from
media_keyvia HKDF - Return decrypted plaintext
media_key is expanded using HKDF-SHA256 to derive:
- 16-byte IV
- 32-byte cipher key
- 32-byte MAC key
Plaintext Media (Newsletter/Channel)
- Download plaintext bytes from CDN (often via
static_url) - Verify SHA-256 hash matches
file_sha256 - Return plaintext (no decryption needed)
Newsletter and channel media is not encrypted. The library automatically detects this when
media_key is absent and switches to plaintext validation.