public static function uploadImageToWorkDrive($modelFolderId, $image)
{
// Set the request headers
$headers = self::getHeaders();
// Set the URL for the Zoho Workdrive upload API endpoint
// Prepare the multipart form data
$postData = [
'parent_id' => $modelFolderId,
'content' => $image,
'filename' => urlencode($image->getClientOriginalName()),
'override-name-exist' => 'false',
];
// Initialize a new cURL session
$ch = curl_init();
// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// Execute the cURL request
$response = curl_exec($ch);
// Get the HTTP status code
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the cURL session
curl_close($ch);
dd($response . $statusCode);
// Check if the request was successful
if ($statusCode >= 200 && $statusCode < 300) {
// Parse the response JSON into an object
$responseData = json_decode($response, true);
// Check if the response contains the uploaded file URL
if (isset($responseData['data']['file_info']['url'])) {
// Return the URL of the uploaded image
return $responseData['data']['file_info']['url'];
} else {
// If the response does not contain the file URL, throw an exception
throw new Exception('Error uploading image: Invalid response format');
}
} else {
// If the request was not successful, throw an exception or handle the error accordingly
throw new Exception('Error uploading image: ' . $response);
}
}