title: Jquery file Drag and Drop giving me an "insecure operation" Error
body: <blockquote>
    <p><strong>Note:</strong></p>
    
    <p>The answers &amp; comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.</p>
    
    <p>See the answer in this question for details as well as a demo:<br><a href="https://stackoverflow.com/q/47515232/584192">How to set file input value programatically (i.e.: when drag-dropping files)?</a></p>
  </blockquote>
  
  <p>I'm trying to implement a drag &amp; drop functionality for uploading images with Jquery.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>upload.html</strong></p>
  
  <pre><code>    &lt;form id ="image_upload_form" action="" method="post" enctype="multipart/form-data"&gt;
  
          &lt;input id="id_image" type="file" name="image"&gt;
          &lt;input type="submit" value="Upload" /&gt;
  
      &lt;/form&gt;
  
      &lt;div id="drop_field"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>image_upload.js</strong></p>
  
  <pre><code>$(document).ready(function() {
      var drop_field = $("#drop_field");
      drop_field.bind('dragover', file_drag_over);
      drop_field.bind('drop', file_select);   
  });
  
  
  
  function file_select(event) {
      event.stopPropagation();
      event.preventDefault();
  
      var file = event.originalEvent.dataTransfer.files [0];
      $("#id_image").val(file);
  }
  
  
  
  function file_drag_over(event) {
      event.stopPropagation();
      event.preventDefault();
  
      event.originalEvent.dataTransfer.dropEffect = "copy";    
  }
  </code></pre>
  
  <p>Everything works fine except when I drop the image file onto the field, it gives me a security error:</p>
  
  <pre><code>SecurityError: The operation is insecure.
      this.value = val;
  </code></pre>
  
  <p>I guess this is happening because I'm trying to modify the "value" attribute of a file input field. What is the right way to upload the file without getting this security error?</p>
  
  <p>Thanks!!</p>