Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django未从nginx上传模块接收POST数据_Django_Post_Upload_Nginx - Fatal编程技术网

django未从nginx上传模块接收POST数据

django未从nginx上传模块接收POST数据,django,post,upload,nginx,Django,Post,Upload,Nginx,请帮我解决这个问题: 我有nginx上传模块和nginx进度模块 如果我在没有nginx的情况下发送表单:我将获得POST数据和request.FILES-所有规范 我没有问题 反面: 如果我用nginx发送表格 我得到了她的文件大小,名字!!但是我没有我表格的数据 我的代码: url.py js nginx.conf location = /upload/share { upload_pass /test/upload/; client_max_body_size 250m;

请帮我解决这个问题: 我有nginx上传模块和nginx进度模块 如果我在没有nginx的情况下发送表单:我将获得POST数据和request.FILES-所有规范 我没有问题 反面: 如果我用nginx发送表格 我得到了她的文件大小,名字!!但是我没有我表格的数据 我的代码: url.py

js

nginx.conf

location = /upload/share {
    upload_pass /test/upload/;
    client_max_body_size 250m;
    upload_store /tmp;
    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";
    upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
    upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
    upload_cleanup 400 404 499 500-505;
    
    upload_limit_rate 16k;
    track_uploads upload 1m;
} 

location = /upload/status {
    report_uploads upload;
}

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 90s;
    proxy_read_timeout 30s;
    proxy_pass http://localhost:8152/;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    track_uploads upload 30s;
}
我在哪里发现这个问题:Nginx,Django,JS

添加rest html:

<form id="upload_form"  method="post" enctype="multipart/form-data" accept-charset="utf-8" class="steps" onsubmit="progress();">{% csrf_token %}
<h3>Upload a new file</h3>
    {{form.as_p}}
 <input type="submit" value="Upload" id="submit" /></p> 
 </form>
    <div id="status" style="display: none;">
  <table width="100%"> 
    <tr><th></th><th>load</th><th>rest</th><th>all</th></tr>
    <tr><td>time:</td><td id="elapsed">∞</td><td id="remaining">∞</td><td id="total">∞</td></tr>
    <tr><td>size:</td><td id="sent">0 b</td><td id="offset">0 b</td><td id="length">0 b</td></tr>
    <tr><td>speed:</td><td id="speed">n/a</td></tr>
  </table>
  <div style="border: 1px solid #c0c0c0;">
      <div style="background: #c0c0c0; width: 0%; text-align: right;" id="bar">0%</div>
  </div>
js all

<script type="text/javascript" charset="utf-8">
    function progress() {
    var ms = new Date().getTime() / 1000;
    rq = 0;
    id = "";
    for (i = 0; i < 32; i++) {
      id += Math.floor(Math.random() * 16).toString(16);
    }
    document.getElementById('upload_form').action = "/upload/share?X-Progress-ID=" + id;;
    document.getElementById('status').style.display = 'block'
    interval = window.setInterval(function () { fetch(id, ms); }, 1000);
    return true;
  }
  function fetch(id, ms) {
    var fetch = new XMLHttpRequest();
    fetch.open("GET", "/upload/status", 1);
    fetch.setRequestHeader("X-Progress-ID", id);
    fetch.onreadystatechange = function () {
      if (fetch.readyState == 4) {
        if (fetch.status == 200) {
          var now = new Date().getTime() / 1000;
          var upload = eval(fetch.responseText);
          if (upload.state == 'uploading') {
            var diff = upload.size - upload.received;
            var rate = upload.received / upload.size;
            var elapsed = now - ms;
            var speed = upload.received - rq; rq = upload.received;
            var remaining = (upload.size - upload.received) / speed;
            var uReceived = parseInt(upload.received) + ' bytes';
            var uDiff = parseInt(diff) + ' bytes';
            var tTotal = parseInt(elapsed + remaining) + ' secs';
            var tElapsed = parseInt(elapsed) + ' secs';
            var tRemaining = parseInt(remaining) + ' secs';
            var percent = Math.round(100*rate) + '%';
            var uSpeed = speed + ' bytes/sec';
            document.getElementById('length').firstChild.nodeValue = parseInt(upload.size) + ' bytes';
            document.getElementById('sent').firstChild.nodeValue = uReceived;
            document.getElementById('offset').firstChild.nodeValue = uDiff;
            document.getElementById('total').firstChild.nodeValue = tTotal;
            document.getElementById('elapsed').firstChild.nodeValue = tElapsed;
            document.getElementById('remaining').firstChild.nodeValue = tRemaining;
            document.getElementById('speed').firstChild.nodeValue = uSpeed;
            document.getElementById('bar').firstChild.nodeValue = percent;
            document.getElementById('bar').style.width = percent
          }
          else {
            window.clearTimeout(interval);
          }
        }
      }
    }
    fetch.send(null);
  }
</script>    
我需要保存在模型数据形式和路径文件

我写信给创作者nginx上传了这个问题 解决此问题简单需要外接程序位置指令: 上传\通过\表单\字段 示例:上传(通行证)表单(字段^我的(姓名)(字段$| ^description$);
感谢Valery Kholodkov

请发布表单htmlyour form=UploadFormrequest的其余部分。post,initial={'file':upfile}没有请求。files当您上载图像或文件时,您需要放置请求。files是的,您提到的方法是标准方法使用表单字段。但另一种使用上传表单字段的方式是nginx上传模块。你可以试试
location = /upload/share {
    upload_pass /test/upload/;
    client_max_body_size 250m;
    upload_store /tmp;
    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";
    upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
    upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
    upload_cleanup 400 404 499 500-505;
    
    upload_limit_rate 16k;
    track_uploads upload 1m;
} 

location = /upload/status {
    report_uploads upload;
}

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 90s;
    proxy_read_timeout 30s;
    proxy_pass http://localhost:8152/;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    track_uploads upload 30s;
}
<form id="upload_form"  method="post" enctype="multipart/form-data" accept-charset="utf-8" class="steps" onsubmit="progress();">{% csrf_token %}
<h3>Upload a new file</h3>
    {{form.as_p}}
 <input type="submit" value="Upload" id="submit" /></p> 
 </form>
    <div id="status" style="display: none;">
  <table width="100%"> 
    <tr><th></th><th>load</th><th>rest</th><th>all</th></tr>
    <tr><td>time:</td><td id="elapsed">∞</td><td id="remaining">∞</td><td id="total">∞</td></tr>
    <tr><td>size:</td><td id="sent">0 b</td><td id="offset">0 b</td><td id="length">0 b</td></tr>
    <tr><td>speed:</td><td id="speed">n/a</td></tr>
  </table>
  <div style="border: 1px solid #c0c0c0;">
      <div style="background: #c0c0c0; width: 0%; text-align: right;" id="bar">0%</div>
  </div>
<script type="text/javascript" charset="utf-8">
    function progress() {
    var ms = new Date().getTime() / 1000;
    rq = 0;
    id = "";
    for (i = 0; i < 32; i++) {
      id += Math.floor(Math.random() * 16).toString(16);
    }
    document.getElementById('upload_form').action = "/upload/share?X-Progress-ID=" + id;;
    document.getElementById('status').style.display = 'block'
    interval = window.setInterval(function () { fetch(id, ms); }, 1000);
    return true;
  }
  function fetch(id, ms) {
    var fetch = new XMLHttpRequest();
    fetch.open("GET", "/upload/status", 1);
    fetch.setRequestHeader("X-Progress-ID", id);
    fetch.onreadystatechange = function () {
      if (fetch.readyState == 4) {
        if (fetch.status == 200) {
          var now = new Date().getTime() / 1000;
          var upload = eval(fetch.responseText);
          if (upload.state == 'uploading') {
            var diff = upload.size - upload.received;
            var rate = upload.received / upload.size;
            var elapsed = now - ms;
            var speed = upload.received - rq; rq = upload.received;
            var remaining = (upload.size - upload.received) / speed;
            var uReceived = parseInt(upload.received) + ' bytes';
            var uDiff = parseInt(diff) + ' bytes';
            var tTotal = parseInt(elapsed + remaining) + ' secs';
            var tElapsed = parseInt(elapsed) + ' secs';
            var tRemaining = parseInt(remaining) + ' secs';
            var percent = Math.round(100*rate) + '%';
            var uSpeed = speed + ' bytes/sec';
            document.getElementById('length').firstChild.nodeValue = parseInt(upload.size) + ' bytes';
            document.getElementById('sent').firstChild.nodeValue = uReceived;
            document.getElementById('offset').firstChild.nodeValue = uDiff;
            document.getElementById('total').firstChild.nodeValue = tTotal;
            document.getElementById('elapsed').firstChild.nodeValue = tElapsed;
            document.getElementById('remaining').firstChild.nodeValue = tRemaining;
            document.getElementById('speed').firstChild.nodeValue = uSpeed;
            document.getElementById('bar').firstChild.nodeValue = percent;
            document.getElementById('bar').style.width = percent
          }
          else {
            window.clearTimeout(interval);
          }
        }
      }
    }
    fetch.send(null);
  }
</script>