Skip to main content
Version: 4.2.0

⬇️ 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/...',
);
paramtyperequireddescription
mediaIdStringyesMedia ID (for downloadMediaById)
mediaUrlStringyesFresh 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 bytes
  • getBytesCopy() — defensive copy
  • getMimeType() — server content-type
  • getFileName() — file name inferred from the URL
  • getLength() — byte length
  • getStatusCode() — HTTP status