Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I´m trying to setup a File Upload Server with nginx. My nginx config:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    upload_progress proxied 1m;

    sendfile        on;

    keepalive_timeout  65;




server {
    listen       80;
    server_name  localhost;

client_max_body_size 5000M;
    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;

    }
location /progress {

    report_uploads proxied;
}
location /upload {
    # Pass altered request body to this location
    upload_pass @after_upload;

    # Store files to this directory
    upload_store /tmp;

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

    upload_set_form_field $upload_field_name.name "$upload_file_name";
            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 "^usession$";

    upload_cleanup 400 404 499 500-505;

    track_uploads proxied 5s;
    }
    location @after_upload {
        proxy_pass http://tornadopastuploadprocessor:8888;
    }


}



}

The Test Upload form with some JS:

<!DOCTYPE html>
<html>
<html>
    <head>
  <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>
    <title>Test upload</title>
</head>
<body>

<form id="upload" enctype="multipart/form-data"
action="/upload" 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"> </div>
 </div>
    <div id="tp">(progress)</div>
   </div>

</body>
    </html>

Upload is Working but when I submit a file and want to check the

 http://url/progress?X-Progress-ID=someid

The returned JSON is always:

({ "state" : "starting" });

So it gets not updated during the Upload.

Any Suggestions?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Your javascript to modify the action attribute is commented out so nginx cannot track the upload under the id you expect it to.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.