Skip to main content

Media

Upload and download media files.

Upload Media

Upload a media file to WhatsApp servers for later use in messages.

POST /api/v1/sessions/{session_id}/media/upload

Request

Send as multipart/form-data:

FieldTypeRequiredDescription
filefileYesThe media file to upload
media_typestringNoType: image, video, audio, document, sticker
mimetypestringNoMIME type (auto-detected if not provided)

Response

{
"url": "https://mmg.whatsapp.net/...",
"direct_path": "/v/t62.7...",
"media_key": "base64-encoded-key",
"file_sha256": "base64-encoded-sha256",
"file_enc_sha256": "base64-encoded-enc-sha256",
"file_length": 12345,
"media_type": "image",
"mimetype": "image/jpeg"
}

Example

curl -X POST http://localhost:3451/api/v1/sessions/my-session/media/upload \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "file=@/path/to/image.jpg" \
-F "media_type=image"

Download Media

Download and decrypt media from WhatsApp using the media parameters received in a message.

POST /api/v1/sessions/{session_id}/media/download

Request Body

{
"direct_path": "/v/t62.7...",
"media_key": "base64-encoded-key",
"file_sha256": "base64-encoded-sha256",
"file_enc_sha256": "base64-encoded-enc-sha256",
"file_length": 12345,
"media_type": "image"
}
FieldTypeRequiredDescription
direct_pathstringYesMedia path from message
media_keystringYesBase64-encoded encryption key
file_sha256stringYesBase64-encoded file hash
file_enc_sha256stringYesBase64-encoded encrypted file hash
file_lengthnumberYesOriginal file size in bytes
media_typestringYesType: image, video, audio, document, sticker

Response

{
"data": "base64-encoded-file-data",
"size": 12345
}

Example

curl -X POST http://localhost:3451/api/v1/sessions/my-session/media/download \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"direct_path": "/v/t62.7118-24/...",
"media_key": "ABC123...",
"file_sha256": "DEF456...",
"file_enc_sha256": "GHI789...",
"file_length": 12345,
"media_type": "image"
}'

Usage with Received Messages

When you receive a media message via webhook, extract the media parameters and use them to download:

// Example: Handle incoming image message
const mediaMessage = webhookPayload.message.imageMessage;

const downloadParams = {
direct_path: mediaMessage.directPath,
media_key: mediaMessage.mediaKey, // Already base64
file_sha256: mediaMessage.fileSha256, // Already base64
file_enc_sha256: mediaMessage.fileEncSha256,
file_length: mediaMessage.fileLength,
media_type: "image"
};

// Download the media
const response = await fetch(`/api/v1/sessions/${sessionId}/media/download`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(downloadParams)
});

const { data, size } = await response.json();
// data is base64-encoded file content
const fileBuffer = Buffer.from(data, 'base64');

Media Types

TypeDescriptionCommon Formats
imagePhotos and imagesJPEG, PNG, WebP
videoVideo filesMP4, 3GPP
audioAudio files and voice notesMP3, OGG, WAV
documentDocuments and other filesPDF, DOCX, any
stickerAnimated or static stickersWebP