⬇️ Download Media
Download the binary content of an image, audio, video, document or sticker.
Media URLs returned by getMedia expire after five minutes. downloadMediaById
fetches a fresh URL and downloads it in one step.
final media = await whatsapp.downloadMediaById(
mediaId: 'MEDIA_ID',
);
if (media.isSuccess()) {
final bytes = media.getBytes();
final mimeType = media.getMimeType();
final fileName = media.getFileName();
final size = media.getLength();
}
If you already have a fresh URL:
final media = await whatsapp.downloadMedia(
mediaUrl: 'https://lookaside.fbsbx.com/whatsapp_business/...',
);
| param | type | required | description |
|---|---|---|---|
mediaId | String | yes | Media ID (for downloadMediaById) |
mediaUrl | String | yes | Fresh download URL (for downloadMedia) |
Incoming media
Media IDs received through webhooks are downloadable for 7 days. Download and store them promptly; the URL itself is short-lived.
Media download methods
isSuccess()getBytes()— raw bytesgetBytesCopy()— defensive copygetMimeType()— servercontent-typegetFileName()— file name inferred from the URLgetLength()— byte lengthgetStatusCode()— HTTP status