WasenderApi - Low Cost WhatsApp API for Developers Upload Media File - API Documentation - WasenderApi - Low Cost WhatsApp API for Developers
WasenderApi API

API Documentation

WasenderApi WhatsApp API

Upload Media File

Messages

POST/api/upload

This documentation details how to use the media upload endpoint, which supports both raw binary and Base64-encoded file uploads.

Upload Media File

POST /api/upload

This endpoint uploads a media file (image, video, audio, sticker, or document) to the server. The file is validated, stored temporarily, and made accessible via a unique URL that is active for 24-hours.

There are two methods for uploading a file:

  1. Raw Binary Upload: Send the file directly as the request body. This is the most efficient method for file uploads from servers or modern web clients.
  2. JSON (Base64) Upload: Send a JSON object containing the Base64-encoded file. This is useful for clients where file data is handled as a string.

Request Method 1: Raw Binary Upload

When uploading a binary file, the Content-Type header is mandatory and must accurately reflect the file's MIME type (e.g., image/jpeg, application/pdf). The server uses this header for validation.

Request Method 2: JSON (Base64) Upload

To upload via Base64, send a request with Content-Type: application/json and a body containing a base64 string. The MIME type can be provided in two ways:

  • Recommended: Provide the full Data URL scheme within the base64 string. The API will automatically parse the MIME type.
  • {
    "base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA..."
    }
  • Alternate: Provide the MIME type in a separate mimetype field. This will override any MIME type found in the Data URL.
  • {
    "mimetype": "image/png",
    "base64": "iVBORw0KGgoAAAANSUhEUgA..."
    }

Validation Rules

The API enforces the following size limits per file category:

  • Documents: 50 MB
  • Images: 16 MB
  • Videos: 16 MB
  • Audio: 16 MB
  • Stickers (webp): 5 MB

Files are also validated by their "magic numbers" to ensure the file content matches its declared type, enhancing security.

Parameters

NameTypeRequiredDescription
base64stringNoThe Base64-encoded file data. Can optionally include the Data URL prefix (e.g., data:image/png;base64,...). Required if using JSON upload method.
mimetypestringNoThe MIME type of the file (e.g., image/png). This is only needed for JSON uploads if the base64 string does not include the Data URL prefix.
Request BodybinaryNoThe request body can either be the raw binary data of the file or a JSON object for Base64 uploads.

Code Examples

# Raw Binary Upload (Recommended)
curl -X POST "https://wasenderapi.com/api/upload" \
  -H "Content-Type: image/jpeg" \
  --data-binary "@path/to/your/image.jpg"

# JSON (Base64) Upload
curl -X POST "https://wasenderapi.com/api/upload" \
  -H "Content-Type: application/json" \
  -d '{
    "base64": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE..."
  }'

Response Examples

{
  "success": true,
  "publicUrl": "https://wasenderapi.com/media/a1b2c3d4-e5f6-7890-abcd-ef1234567890.jpg"
}