asp.net mvc中实现视频自动上传

         在视频上传这儿做了好长时间,想了很多办法。因为想做的是当点击图标的时候就让视频自动开始上传不需要点提交按钮,而上传控件file需要点击提交按钮之后才能上传。        

<body>
    <div class="container">

        <div class="panel ">

            <div class="header">
                <p>上传视频</p>
            </div>
            <div class="panel-body">
                <div class="row-fluid">
                    <div class="picture">
                        <img style="cursor: pointer;" alt="" id="shangchuan" src="../../images/上传图标.jpg" />
                    </div>
                    <div class="picture2">
                      @* @using (Html.BeginForm("Index", "UpLoad", FormMethod.Post, new { enctype = "multipart/form-data" }))
                        { 
                        *@<form name="form1" action="/Upload" method ="post"enctype = "multipart/form-data" ><input type="file" name="file" id="myfile" value="" onchange ="UploadFile();" />
                           @*<input type="submit" name="Submit" id="Submit" />*@ </form>
                                 
                              
                       @* }*@</div>
                </div>
                <div class="t">上传视频,即表示您已同意<a href="Declaration"><strong>校园视频上传服务条款</strong></a>,请勿上传色情,反动等违法视频</div>


                <hr />
            </div>

        </div>
    </div>

</body>

      效果如图:(有待上传。)


   Controller 里:     

public class UpLoadController : Controller
    {
        
         //GET: /UpLoad/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Declaration()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(HttpPostedFileBase file,  uploadModel model)
        {
            if (file.ContentLength > 0)
            {
                //获得保存路径
                string filePath = Path.Combine(HttpContext.Server.MapPath("~/Uploads"),
                                Path.GetFileName(file.FileName));
                file.SaveAs(filePath);

                model.vedio = filePath;
                model.Id = Guid.NewGuid();
                //model.Id=Request["text"];
                uploadDB.UploadModel.AddVedio(model);

               
            }
            return View();
        }

    }
             视频的上传完成了,上传时候的进度条又是一个难点。还要继续攻克。

       

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。