I have this function in codeigniter 4
public function sendChatFile($file, $input)
{
// Check if file size exceeds the limits
$maxImageSize = 16 * 1024 * 1024; // 16 MB
$maxFileSize = 20 * 1024 * 1024; // 20 MB
if ($file->getSize() > $maxImageSize && !in_array($file->getClientMediaType(), ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])) {
throw new Exception('File size exceeds the limit for images (16 MB)');
} elseif ($file->getSize() > $maxFileSize) {
throw new Exception('File size exceeds the limit for other file types (20 MB)');
}
$userId = $input['user_id'];
$zoomFileApiUrl = "https://file.zoom.us/v2/chat/users/{$userId}/messages/files";
$fileData = [];
// Get the binary contents of the file
$fileContents = file_get_contents($file->getPathname());
// Add file data to the array
$fileData = [
[
'name' => 'files',
'contents' => $fileContents,
]
];
if (!empty($input['to_channel_id'])) {
$fileData[] = [
'name' => 'to_channel',
'contents' => $input['to_channel_id']
];
} elseif (!empty($input['to_contact'])) {
$fileData[] = [
'name' => 'to_contact',
'contents' => $input['to_contact']
];
}
if (!empty($input['reply_main_message_id'])) {
$fileData[] = [
'name' => 'reply_main_message_id',
'contents' => $input['reply_main_message_id']
];
}
$client = new Client([
'verify' => false,
]);
try {
$response = $client->post($zoomFileApiUrl, [
'headers' => [
'Authorization' => 'Bearer ' . $this->generateAccessToken(),
],
'multipart' => $fileData,
]);
$responseData = json_decode($response->getBody(), true);
if (isset($responseData['code']) && $responseData['code'] === 1001) {
throw new Exception('Unlicensed Zoom Id');
}
return $responseData;
} catch (ClientException $e) {
$responseBody = $e->getResponse()->getBody()->getContents();
return $responseBody;
} catch (Exception $e) {
return $e->getMessage();
}
}
its giving this error
{“message”:“Invalid parameter: files.”,“code”:300}
where is mistake in my code