Laravel - How to Convert File(image, audio, video) Extension using CloudConvert?

By Hardik Savani April 16, 2024 Category : Laravel

We may sometimes require to convert file extension like if you have video type mov or flv or 3gp etc and you should have to convert it into mp4, OR if you have image type png, jpeg, gif and require to convert it into jpj, Same as for audio mp3, then all the thing you can do using CloudConvert API. you can also convert pdf into jpg using CloudConvert API.

it might be help with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

In this example i use CloudConvert API with Laravel. CloudConvert is a very popular API for convert file extensions. So in this example i used CloudConvert API for any video extension convert into mp4. you can also convert anything as you want like any audio 3gp into mp3 etc.

So, you can convert any video extension into mp4, you have to just follow few step and get example:

1.Package Installation

In first step we have to install cloudconvert-laravel package using composer, so open your terminal and run bellow command:

composer require robbiep/cloudconvert-laravel

After install this package, Now open config/app.php file and add service provider.


'providers' => [




One more after this, we have to publish configuration file of cloudconvert api file. Run bellow command:

php artisan vendor:publish

Now you have configuration file here config/cloudconvert.php, In this file you have to put your API key. If you haven't API key then you can generate from here : And create new account, after email confirmation it will give you API key. you have to just copy that key and put here:


return array(

'api_key' => 'Your API Key',

's3' => [

'accesskeyid' => '',

'secretaccesskey' => '',

'bucket' => '',

'acl' => '',

'region' => ''


'ftp' => [

'host' => '',

'user' => '',

'password' => '',

'port' => 21,

'dir' => '',



2. Add Route

First you have add two route in routes.php file. first one for generate view and second one for post method. so let's add bellow route in your routes.php file.


Route::get('fileUpload', function () {

return view('fileUpload');


Route::post('fileUpload', ['as'=>'fileUpload','uses'=>'HomeController@fileUpload']);

3. Add Controller Function

Ok, now we need to add fileUpload() in HomeController.php file. If you don't have HomeController then you can create new and put bellow code on that file. You must have one folder public/videos with full permission because every video will upload in videos folder.


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use CloudConvert;

class HomeController extends Controller



* Create a new controller instance.


* @return void


public function __construct()




public function fileUpload(Request $request)


$this->validate($request, [

'video' => 'required|mimes:mp4,avi,asf,mov,qt,avchd,flv,swf,mpg,mpeg,mpeg-4,wmv,divx,3gp|max:20480',


$videotmp = time();

$video = $request->file('video');

$input['video'] = $videotmp.'.'.$video->getClientOriginalExtension();

$destinationPath = public_path('/videos');

$video->move($destinationPath, $input['video']);

if($video->getClientOriginalExtension() != "mp4"){


File::delete($destinationPath.'/'. $input['video']);

$input['video'] = $videotmp.'.mp4';


return back()->with('success','Video Upload successful');



4. Create Blade File

In At Last we require to create view file for image or file uploading. so you can create fileUpload.blade.php and put following code in that file.




@if (count($errors) > 0)

<div class="alert alert-danger">

<strong>Whoops!</strong> There were some problems with your input.<br><br>


@foreach ($errors->all() as $error)

<li>{{ $error }}</li>





{!! Form::open(array('route' => 'fileUpload','enctype' => 'multipart/form-data')) !!}

<div class="row cancel">

<div class="col-md-4">

{!! Form::file('video', array('class' => 'video')) !!}


<div class="col-md-4">

<button type="submit" class="btn btn-success">Create</button>



{!! Form::close() !!}


Now you can run, If you want to get more information about package then you can from here : cloudconvert-laravel.

Tags :