dongyingming8970 2013-03-05 09:54
浏览 59
已采纳

上传lighttpd的进度无响应

I am trying to get the uploadprogress module for lighttpd 1.5 to work, but i am running into a strange problem:

When i start the upload "/response" is getting called every second with the X-Progress-ID header set, but i am not getting any response. The GET call is just loading and loading but is getting no response. If call it manually (localhost/response?X-Progress-ID=someID) it appears to be right and the values for recieved and total are right and set. When i then cancel the upload progress (via the "X" Button in the Browser) /response keeps getting called, but now it will return with status 200, but, of course, with no right values set.

Here is my code:

Javascript:

 interval = null;

   function openProgressBar(uuid) {

        /* call the progress-updater every 1000ms */

        interval = window.setInterval(
             function () {
                 fetch(uuid);
              },
              1000
        );
    }

    function fetch(uuid) {
      req = new XMLHttpRequest();
      req.open("GET", "/progress", 1);
      req.setRequestHeader("X-Progress-ID", uuid);
      req.onreadystatechange = function () {
      if (req.readyState == 4) {
        if (req.status == 200) {
            /* poor-man JSON parser */
            var upload = eval(req.responseText);

            document.getElementById('tp').innerHTML = upload.state;

            /* change the width if the inner progress-bar */
            if (upload.state == 'done' || upload.state == 'uploading') {
                bar = document.getElementById('progressbar');
                w = 400 * upload.received / upload.size;
                bar.style.width = w + 'px';
            }
            /* we are done, stop the interval */
            if (upload.state == 'done') {
                window.clearTimeout(interval);
            }
        }
      }
     }
     req.send(null);
    }

And my HTML:

 <form id="upload" enctype="multipart/form-data" 
     action="index.php?X-Progress-ID={{tracking_id}}" 
     method="post" 
     onsubmit="openProgressBar('{{tracking_id}}'); return true;">

     <input name="video" type="file" />
     <input type="submit" class="button orange medium" value="Upload" />

 </form>

 <div>
   <div id="progress">
   <div id="progressbar"></div>
   </div>
   <div id="tp">(progress)</div>
 </div>

EDIT: Forgot to mention...the {{tracking_id}} is getting generated in the php controller and printed with Twig.

展开全部

  • 写回答

1条回答 默认 最新

  • dsh77114 2013-03-06 03:45
    关注

    It seems to be a old bug with Chrome:

    https://code.google.com/p/chromium/issues/detail?id=45196

    Same issue..tested it with Firefox and it worked fine. Sadly this bug does exist for like 2-3 years now, so there is no big hope for a fix in the near future.

    Got it working with uploading the file via XMLHTTPRequest.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥50 关于#php#的问题,请各位专家解答!
  • ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
  • ¥15 IEC61850 客户端和服务端的通讯机制
  • ¥15 MAX98357a(关键词-播放音频)
  • ¥15 Linux误删文件,请求帮助
  • ¥15 IBMP550小型机使用串口登录操作系统
  • ¥15 关于#python#的问题:现已知七自由度机器人的DH参数,利用DH参数求解机器人的逆运动学解目前使用的PSO算法