【问题标题】:asp.net video upload with progress bar带进度条的asp.net视频上传
【发布时间】:2012-12-11 03:40:58
【问题描述】:

我正在尝试使用 XMLhttprequest() 和 html5 进度元素来实现带有进度条的视频上传,如下所示:

    <input type="file" name="fileUpload1" id="fu1" />
    <button type="button" id="clicker" value="Upload" name="Upload" >Upload</button>
    <progress id="prog1"></progress>

和js:

   $("#clicker").live('click', function (e) {
        e.preventDefault();
        UploadVideo("fu1", "");
    });

    function UploadVideo(elm, url) {
         var xhr = new XMLHttpRequest();
         var fd = new FormData();
         fd.append("fu1", document.getElementById("fu1").files[0]);
         xhr.addEventListener("progress", ProcessVideo, false);
         xhr.open("POST", "Handler.ashx");
         xhr.send(fd);
    }

    function ProcessVideo(evt) {
        if (evt.lengthComputable) {
            var prog = document.getElementById("prog1");
            prog.max = evt.total;
            prog.value = evt.loaded;
        }
    }

最后我正在使用这个通用的 ashx 处理程序来处理它:

    public void ProcessRequest (HttpContext context) {
         var file = context.Request.Files["fu1"];
         var savePath = HttpContext.Current.Server.MapPath("~/teees/" + file.FileName);
         file.SaveAs(savePath);
         context.Response.ContentType = "text/plain";
         context.Response.Write("Hello World");
    }

这工作正常,但进度条没有移动它卡在零,然后在上传完成后跳转到 100,这是什么问题?

谢谢

【问题讨论】:

    标签: jquery asp.net xmlhttprequest


    【解决方案1】:

    也许这几行有什么?

      this.xhr = new XMLHttpRequest();
      if ( this.xhr ){
        this.xhr.upload.addEventListener("progress", function(e){ updateProgress(e) }, false);
    
      function updateProgress(){
         if (e.lengthComputable) {
           var currentState = (e.loaded / e.total) * 100;
           //...
         }
       }
    

    【讨论】:

      猜你喜欢
      • 2014-08-17
      • 1970-01-01
      • 2013-05-01
      • 2019-11-13
      • 2021-07-19
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多