<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VideoJs Archives - Nikhil Patel</title>
	<atom:link href="https://nikhilpatel.in/category/videojs/feed/" rel="self" type="application/rss+xml" />
	<link>https://nikhilpatel.in/category/videojs/</link>
	<description>Tech Tips, Tutorials &#38; Innovation at Your Fingertips.</description>
	<lastBuildDate>Sat, 25 Sep 2021 11:51:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.1</generator>

<image>
	<url>https://nikhilpatel.in/wp-content/uploads/2021/01/cropped-np500X500-1-32x32.png</url>
	<title>VideoJs Archives - Nikhil Patel</title>
	<link>https://nikhilpatel.in/category/videojs/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Record &#038; upload video from browser using JS &#038; Laravel-8</title>
		<link>https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/</link>
					<comments>https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/#comments</comments>
		
		<dc:creator><![CDATA[Nikhil Patel]]></dc:creator>
		<pubDate>Sat, 25 Sep 2021 10:25:00 +0000</pubDate>
				<category><![CDATA[Js]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[VideoJs]]></category>
		<category><![CDATA[blade]]></category>
		<category><![CDATA[boostrap]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[videojs]]></category>
		<guid isPermaLink="false">https://nikhilpatel.in/?p=394</guid>

					<description><![CDATA[<p>The post <a href="https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/">Record &#038; upload video from browser using JS &#038; Laravel-8</a> appeared first on <a href="https://nikhilpatel.in">Nikhil Patel</a>.</p>
]]></description>
										<content:encoded><![CDATA[
		<div id="fws_6a56a69d4ce1f"  data-column-margin="default" data-midnight="dark"  class="wpb_row vc_row-fluid vc_row top-level standard_section "  style="padding-top: 0px; padding-bottom: 0px; "><div class="row-bg-wrap" data-bg-animation="none" data-bg-overlay="false"><div class="inner-wrap"><div class="row-bg"  style=""></div></div><div class="row-bg-overlay" ></div></div><div class="row_col_wrap_12 col span_12 dark left">
	<div  class="vc_col-sm-12 wpb_column column_container vc_column_container col no-extra-padding inherit_tablet inherit_phone "  data-t-w-inherits="default" data-bg-cover="" data-padding-pos="all" data-has-bg-color="false" data-bg-color="" data-bg-opacity="1" data-hover-bg="" data-hover-bg-opacity="1" data-animation="" data-delay="0" >
		<div class="vc_column-inner" ><div class="column-bg-overlay-wrap" data-bg-animation="none"><div class="column-bg-overlay"></div></div>
			<div class="wpb_wrapper">
				<div id="fws_6a56a69d4eff3" data-midnight="" data-column-margin="default" class="wpb_row vc_row-fluid vc_row inner_row standard_section   "  style="padding-top: 0px; padding-bottom: 0px; "><div class="row-bg-wrap"> <div class="row-bg" ></div> </div><div class="row_col_wrap_12_inner col span_12  left">
	<div  class="vc_col-sm-12 wpb_column column_container vc_column_container col child_column no-extra-padding inherit_tablet inherit_phone "   data-t-w-inherits="default" data-bg-cover="" data-padding-pos="all" data-has-bg-color="false" data-bg-color="" data-bg-opacity="1" data-hover-bg="" data-hover-bg-opacity="1" data-animation="" data-delay="0">
		<div class="vc_column-inner" ><div class="column-bg-overlay-wrap" data-bg-animation="none"><div class="column-bg-overlay"></div></div>
		<div class="wpb_wrapper">
			
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Hello Folks, we are back with something very interesting topic. Today we are going to learn how we can record and upload the video to the server from the browser using Js &amp; Laravel-8. So lest’s start.</p>
<p>If you are new and don’t know how to setup laravel then don’t worry you can start from scratch by clicking this link <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/" target="_blank" rel="noopener">Laravel Setup &amp; Simple CRUD App.</a></p>
<p>In this demo, we are going to use JS and Laravel-8 and also we will user Ajax to upload a recorded video. Let’s get started step by step.<br />
<em>Note: we are not going to show how to set up laravel here so you can check out our  post <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/" target="_blank" rel="noopener">Laravel Setup &amp; Simple CRUD App</a></em></p>
	</div>
</div>




<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>After installing laravel just follow these steps.</p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 1: Migration &amp; Routing</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>We will create Model, Controller in a single command</p>
<pre><code class="language-nginx"> artisan make:model Media -mcr </code></pre>
<p>A migration file will be created in the database/migrations directory, and we need to create our schema. I added file_name (text) column. I used $table-&gt;timestamps(); it will set created_at and updated_at automatically.<br />
Then run the migration command. And also don’t forget to add <strong>file_name </strong> in <strong>App\Models\Media.php</strong> fillable.</p>
<pre><code class="language-nginx">php artisan migrate</code></pre>
<p>So we have to set a resource route in <strong> routes/web.php </strong></p>
<pre><code class="language-php-extras">use App\Http\Controllers\MediaController;</code></pre>
<p>At top of <strong>routes/web.php</strong> and add following line after that.</p>
<pre><code class="language-php-extras">Route::resource('videos', MediaController::class); </code></pre>
<p>We already learned how to set views and layout in the previous post if you haven’t then just check checkout by clicking this link <a href="https://nikhilpatel.in/laravel-8-simple-crud-app/" target="_blank" rel="noopener">Laravel Setup &amp; Simple CRUD App.</a></p>
<p>Now move to the listing page <strong>index.blade.php</strong> in this you can see a listing of all videos and also have a delete option.</p>
	</div>
</div>



<div class="img-with-aniamtion-wrap " data-max-width="100%" data-max-width-mobile="default" data-border-radius="none" data-shadow="none" data-animation="fade-in" >
      <div class="inner">
        <div class="hover-wrap" data-hover-animation="none"> 
          <div class="hover-wrap-inner">
            <img fetchpriority="high" decoding="async" class="img-with-animation skip-lazy " data-delay="0" height="657" width="1347" data-animation="fade-in" src="https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db.jpg" alt="Record &amp; upload video from browser using JS &amp; Laravel-8" srcset="https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db.jpg 1347w, https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db-300x146.jpg 300w, https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db-1024x499.jpg 1024w, https://nikhilpatel.in/wp-content/uploads/2021/09/App-Name-Video-Record-save-to-db-768x375.jpg 768w" sizes="(min-width: 1450px) 75vw, (min-width: 1000px) 85vw, 100vw" />
          </div>
        </div>
      </div>
    </div>
<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 2: The HTML</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Now we had added 2 video tags one for show recording and another one will show your recorded clip preview.</p>
<p>There is a start button from where you can start recording. Stop button to stop recording, Save button to save the video to the table, and upload the video file to the server.Download the button for recorded video download.</p>
<p>Ideally, these elements aren&#8217;t created until it&#8217;s confirmed that The client supports video/camera, but for the sake of illustrating the elements involved, they are created with markup (not JavaScript).</p>
<p>Here the preview will be hidden until video recording stoped.<br />
<script src="https://gist.github.com/nikhilpatel8000/3b064de6393701e161e9c2f9c0b656bb.js"></script></p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 3: The JavaScript &amp; Access the camera interactively</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>Modern browsers can have a direct line to the camera allowing us to build experiences that are fully integrated with the web page and the user will never leave the browser.</p>
<p><strong>Acquire access to the camera :</strong> <strong>navigator.mediaDevices.getUserMedia</strong>, a simple method sets the<strong>video </strong> element&#8217;s <strong>src</strong> to the user&#8217;s live camera/webcam. Calling the <strong>start</strong> method of the video then starts the element&#8217;s live streaming video connection. That&#8217;s all that&#8217;s required to connect your camera to the browser! Here we are going to record the only video so the audio parameter will be false.</p>
<pre><code>navigator.mediaDevices.getUserMedia({
	video: true,
	audio: false
})</code></pre>
<p>Here we had set a time limit for 5 seconds so video recording automatically will be stopped after 5 seconds. You can change as per your requirement, you have to do is just pass duration in milliseconds like 5000 for 5 seconds.</p>
<p>So we have set <strong>console.log</strong> to track all the activity of the recording task.</p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 4: Show the streaming blob</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating-point numbers, characters, and strings, which store letters and numbers.</p>
<p>Since blobs can store binary data, they can be used to store images or other multimedia files. For example, a photo album could be stored in a database using a blob data type for the images, and a string data type for the captions. Because blobs are used to store objects such as images, audio files, and video clips, they often require significantly more space than other data types.</p>
<p>after the recording stopped we need to set a preview so the user can watch the recorded video he can download or upload to the server.</p>
<p>finally how our recording script looks like.</p>
<p><script src="https://gist.github.com/nikhilpatel8000/e205c612a0d11db3d71a098aacefaf46.js"></script></p>
	</div>
</div>




<div class="nectar-animated-title" data-style="color-strip-reveal" data-color="accent-color">
	<div class="nectar-animated-title-outer">
		<div class="nectar-animated-title-inner">
			<div class="wrap"><h6 style="color: #ffffff;">Step 5: To upload the blob(video) to the server(Laravel-8)</h6></div>
		</div>
	</div>
</div>
<div class="wpb_text_column wpb_content_element " >
	<div class="wpb_wrapper">
		<p>As shown above we had set <strong>form object</strong> to append all the data and then we passed data to the controller. Note that since we passing media objects we need to use the POST method so it&#8217;s required CSRF TOKEN for submit data. So we can set CSRF TOKEN to the meta tag so we can use it anywhere on laravel website.</p>
<pre><code>&lt;meta name="csrf-token" content="{{csrf_token()}}"&gt;</code></pre>
<pre><code>document.querySelector('meta[name="csrf-token"]').getAttribute('content')</code></pre>
<p>Now we have to upload the video file to the server. So we need a directory where all the uploaded videos will be moved. We are using storage to move the file so we need to link storage.<br />
Run the following command to link storage</p>
<pre><code>php artisan storage:link</code></pre>
<p>You will see the <strong>storage</strong> directory like a shortcut icon in your public folder. Now just need to add the directory name and, it will create if that directory not exists and move the uploaded file to the server.</p>
<p>So finally how our App\Http\Controllers\MediaController.php looks like:</p>
<p><script src="https://gist.github.com/nikhilpatel8000/6db17184a181cbee06799538d777c57a.js"></script></p>
<p>Of course, you could add some Audio, Image, and GIF from Browser but I&#8217;ll save that for another post. For now, however, simply accessing the camera in our browser moves us miles ahead. Have fun recording videos within your browser!</p>
	</div>
</div>




		</div> 
	</div>
	</div> 
</div></div>
			</div> 
		</div>
	</div> 
</div></div>
<p>The post <a href="https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/">Record &#038; upload video from browser using JS &#038; Laravel-8</a> appeared first on <a href="https://nikhilpatel.in">Nikhil Patel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nikhilpatel.in/record-upload-video-from-browser-using-js-laravel-8/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
