Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use webuploader to upload video in JavaScript

Shulou Source: shulou.com Published: 2022-05-31 13:06:35 09月24日 Update

This article Xiaobian for you to introduce in detail "how to use webuploader to upload video function in JavaScript", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use webuploader to upload video function in JavaScript" can help you solve your doubts.

Step one, what's the difference between uploading videos and uploading pictures?

In fact, there is no, because all the operations performed are uploads, so we don't have to worry about uploading.

But webuploader actually limits the parameters you upload (in this case, it limits your file extension)

We found the js parameter in webuploader, extensions in accept.

Accept: {title: 'Images',extensions:' gif,jpg,jpeg,bmp,png',mimeTypes: 'image/*'}

We only need to change the suffix such as gif to the format you need to upload (MP4,AVI, etc.)

After this has been changed, our backstage will also make changes.

[HttpPost] public ActionResult upload (HttpPostedFileBase file) {if (file! = null & & file.ContentLength > 0) {string folderpath = "/ UploadFile/"; / / if (! Directory.Exists (folderpath)) {Directory.CreateDirectory (Server.MapPath (folderpath));} string ext1 = Path.GetExtension (file.FileName) If (ext1! = ".mp4" & & ext1! = ".rmvb" & & ext1! = ".avi" & & ext1! = ".flv") / / the author modifies the judgment of the suffix {return Json (new {statu = 201, msg = "incorrect file format!" });} else {string name = DateTime.Now.ToString ("yyyyMMddHHmmssff"); string ext = Path.GetExtension (file.FileName); string downpath = folderpath + name + ext;string filepath = Server.MapPath (folderpath) + name + ext;file.SaveAs (filepath); return Json (new {statu = 200, src = downpath, id = name});} else {return Json (new {statu = 202, msg = "Please upload file!" );}}

The judgment of the background should also be updated.

After we finish this, we will basically have no problem with uploading.

Now open the front-end code.

Upload video upload video / / immediately this will instantiate var uploader with js $(function () {uploader = WebUploader.create ({auto: true, swf:'/ Scripts/Uploader.swf', server:'@ Url.Action ("Upload")', / / Controller pick:'# upl', accept: {title: 'Images', extensions:' mp4,flv,jpeg,bmp,doc,docx,rar,pdf' })}) After reading this, the article "how to use webuploader to upload video in JavaScript" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.

Tags: Videos files functions articles content parameters background suffixes pictures formats problems restrictions appropriateness no use code front end examples actual actually ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB Microsoft Shulou Information NVidia