Unable to upload video file

Published 4 months ago by inzmam

When i am going to upload a video file i m getting an error as "SQLSTATE[HY000]: General error: 1364 Field 'filename' doesn't have a default value (SQL: insert into video_stores (updated_at, created_at) values (2018-03-16 04:14:58, 2018-03-16 04:14:58))".

I don't why this error is being thrown, however i am passing all the values. Please help me in this case.

HomeController:- 'public function uploadVideo(Request $request) { $vid=new VideoStore; if($request->hasFile('Upload_video')) { $video=$request->file('Upload_video'); $filename=time().'.'.$video->getClientOriginalExtension(); $location=public_path('video/'.$filename);

        //Image::make($video)->resize(400,200)->save($location);
       
        $vid->move($location,$filename);
        $vid->filename='inzmam';
         $vid->path='ul haq';
        
    }
    $vid->save();
    Session::flash('success','Your video has been uploaded');
    return redirect()->route('pages.index');
}'

Migration:-

'public function up() { Schema::create('video_stores', function (Blueprint $table) { $table->increments('id'); $table->string('filename'); $table->string('path'); $table->timestamps(); }); }

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('video_stores');
}'.
arthurvillar

This error is telling you exactly what is happening: the if($request->hasFile('Upload_video') returns false, so all the logic within it never runs. The next line that runs is $vid->save(), which is adding only the created_at and updated_at. Laravel adds those automatically behind the scenes every time you insert anything new into your table. This means there is no file coming from your form.

Looks like you don't have enctype="multipart/form-data" in your form tag on the view file. If you don't have that the file will never reach the controller. Your form tag should look like this

<form method="POST" action="/your-route-here" enctype="multipart/form-data">
inzmam

Here is my form

' {{Form::open(['route'=>'pages.uploadVideo','files'=>true])}} {{Form::file('Upload_video',['style'=>'margin-top:10px;'])}} {{Form::submit('Upload Video',['class'=>'btn btn-default','style'=>'margin-top:10px;'])}} {{Form::close()}} '

arthurvillar

Try creating the form without using these helpers from Laravel. Create the actual tag with correct attributes and inputs. It will look like this

<form method="POST" action="/your-route-here" enctype="multipart/form-data">
    <input type="file" name="Upload_video">
    <input type="submit" value="Upload Video" name="submit">
</form>

ps: please use the proper format to post code here, it is very difficult to read it otherwise.

inzmam

Interestingly, i have used FORM facade only to upload images which was uploaded successfully and stored in database table also. Just wanted to ask you if below code is causing an error,

//Image::make($video)->resize(400,200)->save($location);

    $vid->move($location,$filename);
    $vid->filename=$filename;
     $vid->path=$video;
    
arthurvillar

This code is never being reached, so you can't know if it causes errors or not. But by looking at it, I wonder where does the method move() comes from. Looks like $vid is an instance of your VideoStore class, so do you have that method created in there? If not this will fail for sure.

inzmam

$vid is an object of VideoStores model and move function is being used to store the video in video folder under public, do we have any other way out to upload video files and why can't it be done on the same way as i did it to upload images??

Snapey
Snapey
4 months ago (931,125 XP)

just approach it systematically.

dd($vid) and see what it contains


        $vid->move($location,$filename);
        $vid->filename='inzmam';
         $vid->path='ul haq';
    
    dd($vid);
        
    }
    $vid->save();

inzmam

dd($vid) does not contain anything, however when i upload images instead of video it has all the info.

does laravel support video upload or it needs different configuration. I think it needs some different config.

please help me in this case. I am stuck in this since a long time

inzmam

Someone please help me.......

Snapey
Snapey
4 months ago (931,125 XP)

video is just a file

dd($vid) does not contain anything

Well it should, it should at least be an instance of your VideoStore model?

inzmam

thanks for your reply! Yeah it does, meant anything of the uploaded video, but when i upload images, it shows all the info??

Snapey
Snapey
4 months ago (931,125 XP)

this is a two way thing. Dont short change your replies. things like doesnt work and doesnt contain anything are no help.

So, by hitting the dd, we have established that your code thinks there is an uploaded file.

what I cannot understand is if your previous lines are

$vid->filename='inzmam';
$vid->path='ul haq';

why would $vid be empty?

shez1983

how BIG is your video?

inzmam

I am sorry, if it has caused confusion.

$vid->filename='inzmam';
$vid->path='ul haq';

was just written for debugging purpose. However, I have just noticed that my code execution does not enter inside the @if code block.

The actual data that i want to pass into the database table is

 $vid->filename=$filename;
             $vid->path=$path;
inzmam

The video size is just 7MB, i have also configured the php.ini file to increase the max file size.

Please sign in or create an account to participate in this conversation.