Overview
Baileys supports sending various media types efficiently. Media can be provided as aBuffer, Stream, or URL, and Baileys handles encryption and upload automatically.
Media Upload Types
All media messages accept aWAMediaUpload type, which can be:
Using
stream or url is recommended to save memory, especially for large files. Baileys will encrypt the media as a stream without loading the entire file into memory.Image Messages
Send images with optional captions:Image with Mentions
Video Messages
Send video files with captions:Video Notes (PTV)
Send as a video note (circular video):ptv stands for “picture-taking video” - WhatsApp’s internal name for video notes.GIF Messages
Audio Messages
Send audio files or voice notes:Regular Audio
Voice Notes (PTT)
ptt stands for “push to talk” - WhatsApp’s internal name for voice notes.Audio Requirements
For audio to work across all devices, convert to OGG format withffmpeg:
codec: libopus- OGG file formatac: 1- Single audio channelavoid_negative_ts make_zero- Timestamp handling
Audio with Duration
Document Messages
Send any file as a document:Common MIME Types
Sticker Messages
Send stickers (WebP format):Animated Stickers
View Once Messages
Send media that can only be viewed once:viewOnce works with images, videos, and audio messages.Thumbnails
Baileys can automatically generate thumbnails for media messages.Automatic Thumbnail Generation
Install image processing libraries:Manual Thumbnail
Media with Context
Combine media with other message features:Media Upload Process
Understanding how media is uploaded:- Encryption: Media is encrypted using AES-256-CBC
- Upload: Encrypted media is uploaded to WhatsApp servers
- Message: A message containing the media key and URL is sent
- Decryption: Recipient decrypts media using the media key
Media Configuration Options
Configure media upload behavior in socket config:Best Practices
- Use Streams: For large files, use streams to avoid memory issues
- Set MIME Types: Always specify correct MIME types for documents
- Optimize Images: Compress images before sending
- Generate Thumbnails: Install sharp/jimp for automatic thumbnails
- Handle Errors: Wrap uploads in try-catch blocks
- Rate Limiting: Don’t send too many media messages rapidly
Media Message Types
From the Baileys source code:Troubleshooting
Upload Failures
Large Files
For files larger than 100MB, consider:- Breaking into smaller chunks
- Using a more reliable network connection
- Increasing
mediaUploadTimeoutMs
Next Steps
Downloading Media
Learn how to download media from received messages
Message Options
Configure ephemeral and other message options