Samir Shah
Samir Shah

Reputation: 709

How to restrict only video upload using javascript or Jquery?

Hi I have one requirement where I am expecting a lot of video upload traffic but I want to make sure the uploaded file only are videos.

I have not used any uploader plugin for some specific reason.

<input type="file" id="upload" class="btn btn-blue" style="height: 35px;" name="file" /><br />

I am using simple html file type input and I want to restrict only video upload.

I have tried checking extensions but It's lot of extension and difficult to check each one of it.

http://www.fileinfo.com/filetypes/video

Any idea on this?

Upvotes: 1

Views: 6205

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82231

There is no way you can restrict the upload on client side. You should be using server side validation for doing such validations.

You can set the accept attribute as video for input type file. this only show the file-type filtering based on MIME type for the file-select which can be changed by user :

<input type="file" accept="video/*">

for setting through JS:

document.getElementById("upload").accept = "video/*";

Upvotes: 1

Related Questions