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.