title: Sinatra execute code before uploading
body: <p>I'm having a simple HTML form on my page that looks like this:</p>
  
  <pre><code>&lt;form action="/" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="file" /&gt;
      &lt;input type="input" name="pin" /&gt;
      &lt;input type="submit" value="Upload" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Now what I am trying to accomplish (with Sinatra) is to check if the PIN entered into the form field is correct:</p>
  
  <pre><code>post "/" do
      if params[:pin] == "1234"
          start_upload()
      else
          print_error_message()
      end
  end
  </code></pre>
  
  <p>Of course, I want the PIN to be checked before the file starts uploading. But that's my problem. Immediately after clicking the "Upload" button, the file upload starts until it is finished. Then the script checks to see if the PIN is valid.</p>
  
  <p>Is there a way to do stuff before the file upload starts? And if not, what other ways of doing this are there?</p>