title: How to create a drag and drop file uploader for a web page?
body: <p>I have a form that takes file name and file. I am using Bootstrap for formatting it.</p>
  <p>My code (HTML/CSS/JavaScript) is given below:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('input[type="file"]').change(function(e){
          var fileName = e.target.files[0].name;
          $('.custom-file-label').html(fileName);
      });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.form-container {
    background: #fff;
    padding: 30px;
    width: 400px;
    height: 400px;
    border-radius: 10px;
    box-shadow: 0px 0px 10px 0px #000;
    margin-left: 20%;
    margin-bottom: 10%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;!--[if lt IE 7]&gt;      &lt;html class="no-js lt-ie9 lt-ie8 lt-ie7"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 7]&gt;         &lt;html class="no-js lt-ie9 lt-ie8"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 8]&gt;         &lt;html class="no-js lt-ie9"&gt; &lt;![endif]--&gt;
  &lt;!--[if gt IE 8]&gt;&lt;!--&gt; &lt;html class="no-js"&gt; &lt;!--&lt;![endif]--&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
          &lt;title&gt;my test file&lt;/title&gt;
          &lt;meta name="description" content=""&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
          
          &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"&gt;
  
          &lt;link rel="stylesheet" href="new.css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!--[if lt IE 7]&gt;
              &lt;p class="browsehappy"&gt;You are using an &lt;strong&gt;outdated&lt;/strong&gt; browser. Please &lt;a href="#"&gt;upgrade your browser&lt;/a&gt; to improve your experience.&lt;/p&gt;
          &lt;![endif]--&gt;
          &lt;!-- &lt;h1&gt;this is a homepage&lt;/h1&gt; --&gt;
          &lt;form class="form-container" method="POST" enctype="multipart/form-data" action="/result" &gt;
              &lt;!-- {% csrf_token %} --&gt;
              &lt;div class="form-group"&gt;
              &lt;label for="dataname"&gt;Name&lt;/label&gt;
              &lt;input type="text" class="form-control" id="dataname" name="fname" &gt;
              
            &lt;/div&gt;
            &lt;div class="input-group mb-3"&gt;
            &lt;div class="custom-file"&gt;
            &lt;input type="file" class="custom-file-input" id="inputGroupFile02" name="file2"&gt;
            &lt;label class="custom-file-label" for="inputGroupFile02" aria-describedby="inputGroupFileAddon02"&gt;Upload your file here&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    
    
    
    &lt;button type="submit" class="btn btn-primary "&gt;Submit&lt;/button&gt;
          &lt;/form&gt;
  
     
         
  
          &lt;script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"&gt;&lt;/script&gt;
  &lt;script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"&gt;&lt;/script&gt;
  &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"&gt;&lt;/script&gt;
  
          &lt;script src="new.js" async defer&gt;&lt;/script&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I want to have have drag and drop file uploader for single file.</p>
  <p>Desired output should be something like:</p>
  <p><a href="https://i.stack.imgur.com/EPxIa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EPxIa.png" alt="enter image description here" /></a></p>
  <p>The file uploader should be inside the container and should not exceed it.</p>