Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressbar with "vkholodkov/nginx-upload-module" return completed upload when starting #42

Open
Ramel opened this issue Mar 18, 2016 · 0 comments

Comments

@Ramel
Copy link

Ramel commented Mar 18, 2016

Hello,

I'm using this module with the "vkholodkov/nginx-upload-module". And I cannot get the actual upload size. The module always return directly the file length in the remaining variable, see the following Nginx debug log:

2016/03/18 16:21:06 [debug] 25572#0: *6 HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Fri, 18 Mar 2016 15:21:06 GMT
Content-Type: text/javascript
Content-Length: 70
Connection: keep-alive
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache

2016/03/18 16:21:06 [debug] 25572#0: *6 write new buf t:1 f:0 B9385590, pos B9385590, size: 217 file: 0, size: 0
2016/03/18 16:21:06 [debug] 25572#0: *6 http write filter: l:0 f:0 s:217
2016/03/18 16:21:06 [debug] 25572#0: *6 http output filter "/progress?"
2016/03/18 16:21:06 [debug] 25572#0: *6 http copy filter: "/progress?"
2016/03/18 16:21:06 [debug] 25572#0: *6 image filter
2016/03/18 16:21:06 [debug] 25572#0: *6 xslt filter body
2016/03/18 16:21:06 [debug] 25572#0: *6 http postpone filter "/progress?" BFA65158
2016/03/18 16:21:06 [debug] 25572#0: *6 write old buf t:1 f:0 B9385590, pos B9385590, size: 217 file: 0, size: 0
2016/03/18 16:21:06 [debug] 25572#0: *6 write new buf t:1 f:0 B93854E0, pos B93854E0, size: 70 file: 0, size: 0
2016/03/18 16:21:06 [debug] 25572#0: *6 http write filter: l:1 f:0 s:287
2016/03/18 16:21:06 [debug] 25572#0: *6 http write filter limit 0
2016/03/18 16:21:06 [debug] 25572#0: *6 writev: 287 of 287
2016/03/18 16:21:06 [debug] 25572#0: *6 http write filter 00000000
2016/03/18 16:21:06 [debug] 25572#0: *6 http copy filter: 0 "/progress?"
2016/03/18 16:21:06 [debug] 25572#0: *6 http finalize request: 0, "/progress?" a:1, c:1
2016/03/18 16:21:06 [debug] 25572#0: *6 set http keepalive handler
2016/03/18 16:21:06 [debug] 25572#0: *6 http close request
2016/03/18 16:21:06 [debug] 25572#0: *6 http log handler
2016/03/18 16:21:06 [debug] 25572#0: *6 free: B9384BC0, unused: 1066
2016/03/18 16:21:06 [debug] 25572#0: *6 free: B94239F8
2016/03/18 16:21:06 [debug] 25572#0: *6 hc free: 00000000 0
2016/03/18 16:21:06 [debug] 25572#0: *6 hc busy: 00000000 0
2016/03/18 16:21:06 [debug] 25572#0: *6 reusable connection: 1
2016/03/18 16:21:06 [debug] 25572#0: *6 event timer add: 25: 65000:2320617683
2016/03/18 16:21:06 [debug] 25572#0: *6 post event B943E6F4
2016/03/18 16:21:06 [debug] 25572#0: *8 http keepalive handler
2016/03/18 16:21:06 [debug] 25572#0: *8 malloc: B94239F8:1024
2016/03/18 16:21:06 [debug] 25572#0: *8 recv: fd:27 394 of 1024
2016/03/18 16:21:06 [debug] 25572#0: *8 reusable connection: 0
2016/03/18 16:21:06 [debug] 25572#0: *8 posix_memalign: B9384BC0:4096 @16
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "Host: progressbar.localhost"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:45.0) Gecko/20100101 Firefox/45.0"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "Accept-Language: en-US,en;q=0.5"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "Accept-Encoding: gzip, deflate"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "X-Progress-ID: ddb321ec6c4d04c13a83ff9651cdde74"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "Referer: http://progressbar.localhost/"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header: "Connection: keep-alive"
2016/03/18 16:21:06 [debug] 25572#0: *8 http header done
2016/03/18 16:21:06 [debug] 25572#0: *8 generic phase: 0
2016/03/18 16:21:06 [debug] 25572#0: *8 rewrite phase: 1
2016/03/18 16:21:06 [debug] 25572#0: *8 test location: "/"
2016/03/18 16:21:06 [debug] 25572#0: *8 test location: "progress"
2016/03/18 16:21:06 [debug] 25572#0: *8 using configuration "/progress"
2016/03/18 16:21:06 [debug] 25572#0: *8 http cl:-1 max:805306368
2016/03/18 16:21:06 [debug] 25572#0: *8 rewrite phase: 3
2016/03/18 16:21:06 [debug] 25572#0: *8 rewrite phase: 4
2016/03/18 16:21:06 [debug] 25572#0: *8 post rewrite phase: 5
2016/03/18 16:21:06 [debug] 25572#0: *8 generic phase: 6
2016/03/18 16:21:06 [debug] 25572#0: *8 generic phase: 7
2016/03/18 16:21:06 [debug] 25572#0: *8 generic phase: 8
2016/03/18 16:21:06 [debug] 25572#0: *8 access phase: 9
2016/03/18 16:21:06 [debug] 25572#0: *8 access phase: 10
2016/03/18 16:21:06 [debug] 25572#0: *8 access phase: 11
2016/03/18 16:21:06 [debug] 25572#0: *8 access phase: 12
2016/03/18 16:21:06 [debug] 25572#0: *8 post access phase: 13
2016/03/18 16:21:06 [debug] 25572#0: *8 http set discard body
2016/03/18 16:21:06 [debug] 25572#0: *8 upload-progress: get_tracking_id
2016/03/18 16:21:06 [debug] 25572#0: *8 malloc: B9422D20:8
2016/03/18 16:21:06 [debug] 25572#0: *8 upload-progress: get_tracking_id found header: ddb321ec6c4d04c13a83ff9651cdde74
2016/03/18 16:21:06 [debug] 25572#0: *8 reportuploads handler found id: ddb321ec6c4d04c13a83ff9651cdde74
2016/03/18 16:21:06 [debug] 25572#0: *8 upload-progress: find_node ddb321ec6c4d04c13a83ff9651cdde74
2016/03/18 16:21:06 [debug] 25572#0: *8 upload-progress: found node
2016/03/18 16:21:06 [debug] 25572#0: *8 reportuploads found node: ddb321ec6c4d04c13a83ff9651cdde74 (rest: 0, length: 3119977, done: 0, err_status: 0)
2016/03/18 16:21:06 [debug] 25572#0: *8 http script copy: "({ "state" : "uploading", "received" : "
2016/03/18 16:21:06 [debug] 25572#0: *8 http script var: "3119977"
2016/03/18 16:21:06 [debug] 25572#0: *8 http script copy: ", "size" : "
2016/03/18 16:21:06 [debug] 25572#0: *8 http script var: "3119977"
2016/03/18 16:21:06 [debug] 25572#0: *8 http script copy: " });"

nginx version: nginx/1.8.1
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --with-debug --with-cc-opt='-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/headers-more-nginx-module --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-auth-pam --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-cache-purge --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-dav-ext-module --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-development-kit --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-echo --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/ngx-fancyindex --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-http-push --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-lua --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-upstream-fair --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/ngx_http_substitutions_filter_module --add-module=/opt/rebuildnginx/nginx-1.8.1/debian/modules/nginx-upload-progress --add-module=/opt/nginx-upload-module-2.2

nginx.conf:

server {
  listen       127.0.0.1 default;
  server_name  _ ;
  root /var/www/progress-bar;
  index index.html;
  client_max_body_size 768M;
  error_page 405 = $uri;
}
server {
  listen 80;
  listen  127.0.0.1:80;
  server_name progressbar.localhost;

  client_max_body_size 768M;

  error_log /var/log/nginx/error_progressbar.log debug;

  location / {
      # # proxy to upstream server
       proxy_pass http://127.0.0.1;
       proxy_redirect default;

      location ~* upload$ {
          # Pass altered request body to this location
          upload_pass   @uploading;

          # Store files to this directory
          # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
          upload_store /tmp/uploads2;

          # Allow uploaded files to be read only by user
          upload_store_access user:rw;

          # Set specified fields in request body
          upload_set_form_field "${upload_field_name}_name" $upload_file_name;
          upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
          upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;

          # Inform backend about hash and size of a file
          upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
          upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;

          upload_pass_form_field "^submit$|^description$";
     }
     # track uploads in the 'proxied' zone
     # remember connections for 30s after they finished
     track_uploads proxied 30s;
  }

  location @uploading {
    proxy_pass http://127.0.0.1;
  }

  location ^~ /progress {
      # report uploads tracked in the 'proxied' zone
      report_uploads proxied;
  }
}

index.html

<html>
<head>  
</head>                          
<body>            
 <form id="upload" enctype="multipart/form-data" 
    action="/index.html" method="post"
    onsubmit="openProgressBar(); return true;">
  <!--<input type="hidden" name="MAX_FILE_SIZE" value="30000000"  />-->
  <input name="userfile" type="file" label="fileupload" />
  <input type="submit" value="Send File" />
  </form>   
<div>                       
   <div id="progress" style="width: 400px; border: 1px solid black">
    <div id="progressbar" 
       style="width: 1px; background-color: black; border: 1px solid white">
     &nbsp;                                           
    </div>                                             
   </div>                                                   
   <div id="tp">(progress)</div>                                          
  </div>                          
<script type="text/javascript">               
interval = null;               

function openProgressBar() {
 /* generate random progress-id */                    
 uuid = "";                        
 for (i = 0; i < 32; i++) {
  uuid += Math.floor(Math.random() * 16).toString(16);
 }          
 /* patch the form-action tag to include the progress-id */
 document.getElementById("upload").action="/upload?X-Progress-ID=" + 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);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant