Skip to content

Instantly share code, notes, and snippets.

@cybernerdie
Last active February 17, 2023 09:13
Show Gist options
  • Save cybernerdie/a984e95fa39fc8f1fc1f7e274b5f7dec to your computer and use it in GitHub Desktop.
Save cybernerdie/a984e95fa39fc8f1fc1f7e274b5f7dec to your computer and use it in GitHub Desktop.
Upload image to cloudinary in Laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class CloudinaryController extends Controller
public function uploadImageToCloudinary(Request $request)
{
$file = $request->file('image');
$cloudName = 'your_cloud_name';
$uploadPreset = 'your_upload_preset';
$url = 'http://api.cloudinary.com/v1_1/' . $cloudName . '/image/upload?upload_preset=' . $uploadPreset;
$filePath = $file->getRealPath();
$base64 = base64_encode(file_get_contents($filePath));
$response = Http::post($url, [
'file' => "data:{$file->getClientMimeType()};base64,{$base64}",
'multiple' => true,
]);
return $response->body();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment