Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the code that uses webuploader to upload video in JavaScript

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article, Xiaobian introduces in detail "how to write the code for uploading video using webuploader in JavaScript". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to write the code for uploading video using webuploader 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 write the code for uploading video using webuploader in JavaScript" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report