Skip to main content
Media utility functions handle all aspects of media messages including downloading, encryption, thumbnail generation, and media upload preparation.

downloadMediaMessage

Downloads media from a WhatsApp message.
WAMessage
required
The message containing media to download
'buffer' | 'stream'
required
Whether to return a Buffer or a Stream
MediaDownloadOptions
required
Download options including byte range
DownloadMediaMessageContext
Context with reupload request handler and logger

MediaDownloadOptions

number
Start byte for partial download
number
End byte for partial download
RequestInit
Fetch options for the download request
Buffer | Transform
Downloaded media as Buffer (type=‘buffer’) or Stream (type=‘stream’)
Example:
When to use:
  • To download images, videos, audio, documents from messages
  • For saving media to disk
  • When processing media files (thumbnails, transcoding, etc.)
  • Automatically handles media decryption

downloadContentFromMessage

Downloads and decrypts media content from a downloadable message.
DownloadableMessage
required
Object containing mediaKey, directPath, and/or url
MediaType
required
Type of media: ‘image’, ‘video’, ‘audio’, ‘document’, ‘sticker’, etc.
MediaDownloadOptions
Download options
Transform
Decrypted media stream
Example:
When to use:
  • For lower-level media downloading
  • When you have the media message properties directly
  • For streaming large files

encryptedStream

Encrypts media for upload to WhatsApp servers.
WAMediaUpload
required
Media to encrypt (Buffer, Stream, or URL object)
MediaType
required
Type of media being encrypted
EncryptedStreamOptions
Encryption options

EncryptedStreamOptions

boolean
default:false
Whether to save the original unencrypted file
ILogger
Logger instance
RequestInit
Fetch options if media is a URL
object
Object containing encryption keys, file paths, hashes, and file length
Example:
When to use:
  • Before uploading media to WhatsApp
  • Automatically called by sendMessage with media
  • For manual media upload workflows

generateThumbnail

Generates a JPEG thumbnail for images or videos.
string
required
Path to the media file
'video' | 'image'
required
Type of media
object
required
Options with optional logger
object
Object with base64 thumbnail and original dimensions (for images)
Example:
When to use:
  • Automatically used when sending images/videos
  • For generating preview thumbnails
  • Requires ffmpeg for video thumbnails
  • Requires sharp or jimp for image thumbnails

getAudioDuration

Gets the duration of an audio file in seconds.
Buffer | string | Readable
required
Audio file as Buffer, file path string, or Readable stream
number | undefined
Audio duration in seconds
Example:
When to use:
  • Automatically used when sending audio messages
  • For displaying audio duration in UI
  • Requires music-metadata package

getRawMediaUploadData

Prepares raw media data for upload (used for newsletters).
WAMediaUpload
required
Media to prepare (Buffer, Stream, or URL)
MediaType
required
Type of media
ILogger
Logger instance
object
Object with file path, SHA256 hash, and file length
Example:
When to use:
  • When uploading media to newsletters
  • For unencrypted media uploads
  • Automatically used internally for newsletter messages

generateProfilePicture

Generates a profile picture by resizing and cropping an image.
WAMediaUpload
required
Image to process (Buffer, Stream, or URL)
{ width: number; height: number }
Target dimensions (default: 640x640)
{ img: Buffer }
Processed profile picture as JPEG buffer
Example:
When to use:
  • When updating profile pictures
  • Automatically resizes and crops to square
  • Requires sharp or jimp library