I am unable to send media files especially images(jpeg) using the Clickatel One API.
However, text messages are being delivered.
Below is my code snippet for sending the file: (PHP)
$header = [
'Authorization: ' . $clickatel_api_key,
'Content-Type: image/jpeg'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, 'https://platform.clickatell.com/v1/media?fileName=' . $name . '&to=254712345678');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
Below is the response from the request:
{"error":null,"fileId":"2eee5d0eee4fc4f42943e47c06f12345fdss2ddd.jpg","accepted":true}
The media file is not delivered.
I think the API call you do in your example uploads a file and returns a file ID. Next you must send a message (another HTTP POST) using that file ID, example:
The alternative is to do one HTTP request that contains the file data inline:
The examples in the Clickatell documentation that I refer to are called:
If you use the method to send by reference (involving two HTTP requests), it would be beneficial to reuse your curl object ($ch) between all HTTP requests (even for other messages) so that you reuse your HTTP connection for lower latency and reduced CPU usage on your side.