Upload media

To send an image, a PDF or any other file, upload it first. You get back a med_ id, and that id is what you send — not the bytes. Upload once, send it to a thousand people.

Upload

const media = await msg.media.upload(file, "invoice.pdf");
// media.id -> "med_7c1d2e3f..."

The file is stored and registered with WhatsApp in the same call, so the id works immediately — there is nothing to wait for and no second step.

What comes back

FieldWhat it is
idThe med_ id. This is what you send with.
filenameThe name you uploaded it under.
mimeTypeThe type we normalised to, which may differ from the one you declared.
sizeBytesSize of the stored file.

Size limits

WhatsApp caps each kind of file, and we check before storing anything, so an oversized file is refused at upload rather than at send.

KindCap
Image5 MB
Video, audio16 MB
Document100 MB
Sticker500 KB

Keep the id. Uploading the same file again gives you a second copy and a second id.

A test key uploads for real — see Test keys and the sandbox.

Then send it

Pass the id as mediaId — see Send a message.