Skip to main content

Overview

Baileys supports sending various media types efficiently. Media can be provided as a Buffer, Stream, or URL, and Baileys handles encryption and upload automatically.

Media Upload Types

All media messages accept a WAMediaUpload 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

WhatsApp doesn’t support actual .gif files. GIFs are sent as MP4 videos with the gifPlayback flag.

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 with ffmpeg:
Required flags:
  • codec: libopus - OGG file format
  • ac: 1 - Single audio channel
  • avoid_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:
  1. Encryption: Media is encrypted using AES-256-CBC
  2. Upload: Encrypted media is uploaded to WhatsApp servers
  3. Message: A message containing the media key and URL is sent
  4. Decryption: Recipient decrypts media using the media key

Media Configuration Options

Configure media upload behavior in socket config:

Best Practices

  1. Use Streams: For large files, use streams to avoid memory issues
  2. Set MIME Types: Always specify correct MIME types for documents
  3. Optimize Images: Compress images before sending
  4. Generate Thumbnails: Install sharp/jimp for automatic thumbnails
  5. Handle Errors: Wrap uploads in try-catch blocks
  6. 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