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
Last updated
We will explain what “Upload from file” means and show how to do it in different programming languages using the multipart/form-data format
Last updated
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())
<?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;
?>
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));