Project

General

Profile

Docs ModUploadProgress » History » Revision 17

Revision 16 (gstrauss, 2016-09-11 00:55) → Revision 17/22 (gaborca, 2018-08-20 14:18)

h1. Module mod_uploadprogress 

 {{>toc}} 

 h2. Options 

 h3. upload-progress.progress-url 

 string, empty by default; use "/progress" (or something else) to enable the module 

 h3. upload-progress.remove-timeout 

 integer, default: 60 seconds 

 h3. upload-progress.debug 

 boolean, default: "disable" 

 h2. Config Example 

 <pre> 
 upload-progress.progress-url = "/progress" 
 upload-progress.remove-timeout = 30 
 upload-progress.debug = "enable" 
 </pre> 

 h2. Warning 

 This module will not work if you are using more than one worker ("server.max-worker":Server.max-workerDetails) 

 h2. Description 

 As of version 1.4.42 this This module can be used to track the progress of a current upload. 

 If you want to track the progress of When a file upload, you have upload is done, the current received bytes are tracked 
 with this module and can be retrieved via the progress-url and the 
 tracking key. This key has to call 
 your be added to the upload processing url with an extra parameter called X-Progress-ID or via 
 header. 

 In combination with a 32 byte length unique string. 

 <pre> server.max-request-size, usually the browser 
 https://www.my-domain.com/uploadfile.php?X-Progress-ID=abcdefghabcdefghabcdefghabcdefgh will display an error page containing information that the connection 
 </pre> 

 While uploading you has been terminated. This can ping your upload progress url not be replaced with the above a custom error 
 parameter using page, the GET method. browsers aren't displaying them. 

 The uploadprogress module tracks this errors now. If you are not using GET method or the parameter length upload 
 is not 32, 
 you done in one window (or an iframe which will get be hidden on form submit),  
 another iframe can display a 404 response. 

 <pre> 
 https://www.my-domain.com/progress?X-Progress-ID=abcdefghabcdefghabcdefghabcdefgh 
 </pre> 

 custom uploadprogress page which can  
 also fetch the status 413 via json if this happen. If there 413 is no upload progress with that identifier then you get retrieved, 
 a custom error message (File is too big) can be displayed. 

 The first examples can be found at  
 http://blog.lighttpd.net/articles/2006/08/01/mod_uploadprogress-is-back 

 The mentioned multi-frame example will be added in the following response without the quotes: "not in progress". future. 

 h2. How to use it 

 Generate a progress-id (32 hex digits - just use a md5 hash); send this progress-id in the upload request and in all progress requests, either as "X-Progress-ID" header or as "X-Progress-ID" query string parameter. 

 h2. XML JSON Response 

 The returned XML will look like this: json may contain: 
 <pre> * state 
   current state of upload 
   values = starting, error, done, uploading 
 <?xml version="1.0" encoding="iso-8859-1"?><upload><size>14953670</size><received>391182</received></upload> * status 
   http error status 
   values = 413 
 </pre> * size 
   size of request 
 * received 
   bytes received by lighttpd yet 

 h2. Example 1 

 Three html-files are appended as example, based on Jan's work mentioned 
 at the link above. You need to add the tracking_id (an example how this is 
 done with a single page upload and javascript is also provided at Jan's blog). 

 In the iframe version, you can generate the tracking_id via php or other 
 server-side scripting. 

 Warning, the files are not working out of the box, you have to change things! 

 Downloads: 
 * index.html    - main page 
   attachment:index.html 

 * status.html - page containing progress  
   attachment:status.html 

 * upload.html - page posting the file     
   attachment:upload.html 

 h2. Example 2 

 <pre><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
 <html> 
 <head> 
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
	 <title>File upload progress</title> 
 </head> 
 <body> 
   <form action="?X-Progress-ID=a2345678901234567890123456789012" method="POST" enctype="multipart/form-data" id="upload" target="upload_frame"> 
     <input type="file" name="file"> 
     <input type="submit"> 
   </form> 
   <iframe width="0" height="0" frameborder="0" scrolling="no" name="upload_frame" id="upload_frame"></iframe> 
   <p><button type="button" id="button">state</button> <span id="state"></span></p> 
 <script> 
 function get_state() { 
   var xhr = window.XMLHttpRequest ? Theres a new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); 

   function handle() { 
     if (xhr.readyState != 4) { 
       return; 
     } 
     var v = xhr.responseText; 
     if (v === 'not in progress') { 
       state.innerHTML = 'done'; 
       clearInterval(timer); 
       return; 
     } 
     var arr = reg.exec(v); 
     state.innerHTML = Math.floor(100 * arr[2] / arr[1]) + '%'; 
   } 

   xhr.open('GET', '/progress?t=' + new Date().getTime(), true); 
   xhr.setRequestHeader('X-Progress-ID', 'a2345678901234567890123456789012'); 
   xhr.onreadystatechange = handle; 
   xhr.send(); example (using YUI framework) here: 
 } http://redmine.lighttpd.net/attachments/399/index.2.html 


 h2. mod_uploadprogress for lighttpd-1.4 branch 

 var reg = new RegExp('size>([0-9]+)</size><received>([0-9]+)</rec'), timer; I've backported mod_uploadprogress so you may use it together with lighttpd-1.4 branch if interested. You may download the patch at http://labs.logic.cz/patches/lighttpd/1.4.x/ 

 function start_interval() { 
   timer = setInterval(get_state, 1000); 
 } Don't expect exactly the same behavior as this version returns JSON object for better integration with frameworks like Dojo. I've also tweaked the key names and some values returned. 

 var button = document.getElementById('button'), upload = document.getElementById('upload'), state = document.getElementById('state'), upload_frame = document.getElementById('upload_frame'), f = upload_frame.contentWindow; 

 upload.onsubmit = start_interval; 
 </script> 
 </body> 
 </html></pre> We're using this patch for about half a year and it seems stable. Enjoy! ;-)