I am trying to send image from an html page to Django view. But I am not able to attain the data. The following is my code.
<input type="file" id = "imageupload" onchange = "sendimg()" />
<script>
  var sendimg = function(){
    var img = document.getElementById("imageupload")
    $.ajax({
      type: "POST",
      url: "/test/",
      data: {
        "imgfile": img,
      },
      processData: false,
      contentType: false,
      success: function(data){
        console.log("success");
        console.log(data);
      },
      failure: function(data){
        console.log("failure");
        console.log(data);
      },
    });
  }
</script>
The Django view is
@csrf_exempt
def testimg(request):
  print "the request",request.POST
  data = {"data": "ok"}
  return JsonResponse(data)
The print statement gives
the request <QueryDict: {}>
What am I doing wrong ?
 
     
     
    