Help Desk
  • Getting Started
    • 🙌Welcome to Whapi.Cloud
    • 💰Pricing
    • ☕Partners
    • 🚀Getting started
    • 👨‍💻API Docs
      • Developer hubs
      • Swagger environment
      • Postman collection
  • Sending
    • Introduction
    • Send text message
      • Whatsapp API send message PHP
      • Whatsapp API send message Python
      • Whatsapp API send message Node JS
      • Whatsapp API send message С#
      • Whatsapp API send message Java
      • API integration with VB6
      • Whatsapp API send message GO (Golang)
    • Send video, audio, image, document
      • How to send file from your local computer using the API
    • Send Group message
    • Send post to WhatsApp Channel
    • Send message with Buttons
    • Send Emoji
    • Overview of other methods for sending
      • Send Voice message
      • How to generate a waveform for a voice message
      • Send contact (vCard)
      • Send message reactions
  • Receiving
    • Introduction
    • Webhooks
      • Our webhooks (Tracked events)
      • Where to Find the Webhook URL?
      • Set the webhook link to the channel
      • Detailed webhook settings
      • How to check the webhook?
      • Incoming webhooks format
        • Incoming message
        • Sent message
        • Chats
          • How to Track Chat Labels via Webhook
        • Groups
        • Communities
        • Contacts
        • Account and device status
        • Other
          • Calls
          • Presences
          • Labels
          • Views of stories (statuses)
          • Story (status) from your contacts
      • Receive messages
        • Receive WhatsApp messages using PHP
        • Receive WhatsApp messages using Node js
        • Receive WhatsApp messages using Python
    • HTTP API
      • How to retrieve files
      • Retrieve a Specific User's Chat History
      • Get a full-size picture in the response
      • Get order items
      • Get a profile picture of a chat or user
    • File expiration period
  • Groups
    • Send Group message
      • Mentioning all participants in a WhatsApp group
    • Get list of group members
    • Add new member to Group
  • What Is lid in WhatsApp Groups?
  • Channels
    • Send post to WhatsApp Channel
    • Get messages from Channels
    • Get votes from polls in the Channel
  • Communities
    • Introduction
    • Create a community
    • Add a member to a community
    • Send announcement
    • Get info on community participants
    • Add a group / Exclude a group from the community
  • Account
    • Setting "Auto Download"
    • Customizable Webhook Headers
    • How to find out the IP channel
    • How to Delete a Channel
    • Add Business Info to Invoice
  • Source code
    • WhatsApp ChatBot
      • WhatsApp Python Bot
      • WhatsApp PHP Bot
      • WhatsApp Node JS Bot
      • WhatsApp Java Bot
    • WhatsApp API Google Sheets
    • WhatsApp Phone Number Checker
    • Request Distributor (Balancer)
  • FAQ
    • Does WhatsApp API work with the phone turned off?
    • Chat ID. What is it and how to get it?
    • Why do I see status "pending" after sending message?
    • How to send a paragraph (line break)
    • Inactive Links in WhatsApp Messages
    • WhatsApp Text Formatting
    • Checking if the number has Whatsapp
    • Specifics of sending messages to numbers of different countries
    • Current status of Buttons on WhatsApp
    • Why aren't participants being added to the group?
  • Hints
    • Android Emulators
    • Virtual Numbers for WhatsApp
    • How to use polls as buttons?
    • How to check who blocked you in Whatsapp?
    • Setting up a WhatsApp proxy
  • Integrations
    • Make.com
      • Ready-Made Scenarios
        • WhatsApp & Whisper API: Voice-to-Text Integration
        • Automated WhatsApp Group Message Forwarding in Make.com
      • Request Scenario Setup
    • Pabbly Connect
    • Google Contacts
    • DialogFlow
    • n8n
  • Tools
    • WhatsApp Number Checker
    • Automatic warm-up module
    • WhatsApp Activity Safety Meter
    • Residential Proxies from Whapi.Cloud
  • Troubleshooting
    • Couldn't Link Device – WhatsApp QR Code or Pairing Code Fails
    • Channel status “SYNC_ERROR”
    • Not getting a READ status on webhook
    • 429 (Too Many Requests) - Soft Ban
    • “Waiting for this message. This may take a while” – WhatsApp Message Error
    • Missing push notifications after connecting to API
  • Blocking
    • How to not get Banned?
    • How to do mailings without the risk of being blocked?
    • If My Number Is Banned, Can It Be Restored?
    • Unlocking Your WhatsApp Number
    • Connecting a New WhatsApp Number After a Ban: Steps and Recommendations
    • Warming Up New Phone Numbers for WhatsApp API
  • Partner Documentation
    • Introduction
    • Partner Dashboard Overview
    • Partner Program Guidelines
      • Workflow: Step-by-Step
      • Billing for Partners
      • Allocating Days to Customer Channels: Best Practices & Guide
      • Interface for channel management
    • Partner Documentation
      • Channel creation
      • Changing channel mode
      • Channel extension
      • Channel deletion
      • Getting the list of channels
      • Notices of end of days on balance
Powered by GitBook
On this page

Was this helpful?

  1. Sending
  2. Send video, audio, image, document

How to send file from your local computer using the API

We will explain what “Upload from file” means and show how to do it in different programming languages using the multipart/form-data format

Whapi.Cloud supports sending media files (images, documents, audio, etc.) using several methods:

  • By URL;

  • By Base64;

  • By media ID (after a file is uploaded);

  • By directly uploading the file from your local computer;

This article explains how to use the "Upload from file" option — one of the most commonly misunderstood steps for new developers.


One of the most common points of confusion for new developers working with media upload is the "Upload from File" option. While uploading by URL or Base64 is relatively straightforward, sending a file from your local machine using code requires a clear understanding of how multipart/form-data works in HTTP.

What Does "Upload from File" Mean?

When using "Media with upload from file", you are expected to send the file as binary data (not a path or URL) inside the request body using the multipart/form-data format. This is the same method used when uploading files through forms on websites.

⚠️ A common mistake is trying to send a local file path or localhost URL like: "media": "http://localhost:8080/files/logo.png" This will not work — the API doesn't know how to access your local system.

Instead, you must send the actual file content as part of the HTTP request.

Sending a media file works via multipart/form-data or via a Base64 string with the appropriate prefix. Both methods are valid. You can choose the one that best suits your development environment.

Read more about Sending File as Base64.

Sending File via multipart/form-data

You can upload the file directly in binary form using multipart/form-data. This is how file uploads typically work in forms and in Postman.

Examples:

curl -X POST https://gate.whapi.cloud/messages/image \
  -H "Authorization: Bearer {YOUR_TOKEN}" \
  -F 'to=919984351847' \
  -F 'caption=Hello, this message was sent via API!' \
  -F 'media=@/path/to/your/file.png'
import requests

url = 'https://gate.whapi.cloud/messages/image'
token = 'YOUR_TOKEN'

data = {
    'to': '919984351847',
    'caption': 'Hello, this message was sent via API!'
}

files = {
    'media': open('file.png', 'rb')
}

headers = {
    'Authorization': f'Bearer {token}'
}

response = requests.post(url, data=data, files=files, headers=headers)
print(response.json())

Note: Python automatically formats the request as multipart/form-data when using the files parameter.

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://gate.whapi.cloud/messages/image');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = [
    'Authorization: Bearer YOUR_TOKEN'
];

$data = [
    'to' => '919984351847',
    'caption' => 'Hello, this message was sent via API!',
    'media' => new CURLFile('file.png')
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>

Note: CURLFile ensures that the file is sent as multipart/form-data. The API will handle the rest.

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

const form = new FormData();
form.append('to', '919984351847');
form.append('caption', 'Hello, this message was sent via API!');
form.append('media', fs.createReadStream('./file.png'));

axios.post('https://gate.whapi.cloud/messages/image', form, {
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    ...form.getHeaders()
  }
})
.then(response => console.log(response.data))
.catch(error => console.error(error.response?.data || error.message));

PreviousSend video, audio, image, documentNextSend Group message

Last updated 1 month ago

Was this helpful?