title: How to upload multiple files separately in Flask?
body: <p>Here is the problem I have. I need to create a web app capable of uploading two files of separate types (wav files and midi/MusicXML files respectively). Right now this does not work.
  Here is my code:</p>
  
  <p><code>app.py</code></p>
  
  <pre><code>flask import Flask
  
  UPLOAD_FOLDER = '/Users/CatLover/Documents/DataScience/Insight/FrontEnd/Kitty/files/'
  
  app = Flask(__name__)
  app.secret_key = "secret key"
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
  </code></pre>
  
  <p><code>main.py</code>
      import os
      #import magic
      import urllib.request
      from app import app
      from flask import Flask, flash, request, redirect, render_template
      from werkzeug.utils import secure_filename</p>
  
  <pre><code>ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
  
  def allowed_file(filename):
      return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
  
  @app.route('/')
  def upload_form():
      return render_template('upload.html')
  
  @app.route('/', methods=['POST'])
  def upload_file():
          if request.method == 'POST':
                  print(request.__dict__)
          # check if the post request has the file part
                  if 'file' not in request.files:
                          flash('No file part')
                          return redirect(request.url)
                  file = request.files['file']
                  if file.filename == '':
                          flash('No file selected for uploading')
                          return redirect(request.url)
                  if file and allowed_file(file.filename):
                          filename = secure_filename(file.filename)
                          file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                          flash('File successfully uploaded')
                          return redirect('/')
                  else:
                          flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
                          return redirect(request.url)
  
  if __name__ == "__main__":
          app.run(host="127.0.0.1",port=int("5003"),debug=True)
  </code></pre>
  
  <p><code>templates/upload.html</code>:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;title&gt;Python Flask File Upload Example&lt;/title&gt;
  &lt;h2&gt;Step 1: Select a sheet music file (.xml, .mxl or .mid) to upload&lt;/h2&gt;
  &lt;p&gt;
      {% with messages = get_flashed_messages() %}
        {% if messages %}
          &lt;ul class=flashes&gt;
          {% for message in messages %}
            &lt;li&gt;{{ message }}&lt;/li&gt;
          {% endfor %}
          &lt;/ul&gt;
        {% endif %}
      {% endwith %}
  &lt;/p&gt;
  &lt;form method="post" name="sform" action="/" enctype="multipart/form-data"&gt;
      &lt;dl&gt;
          &lt;p&gt;
              &lt;input type="file" name="sfile" autocomplete="off" required&gt;
          &lt;/p&gt;
      &lt;/dl&gt;
      &lt;p&gt;
          &lt;input type="submit" name="ssubmit" value="Submit"&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  &lt;h2&gt;Step 2: Select a wav file to upload&lt;/h2&gt;
  &lt;form method="post" name="wform" action="/" enctype="multipart/form-data"&gt;
      &lt;dl&gt;
          &lt;p&gt;
              &lt;input type="file" name="wfile" autocomplete="off" required&gt;
          &lt;/p&gt;
      &lt;/dl&gt;
      &lt;p&gt;
          &lt;input type="submit" name="wsubmit" value="Submit"&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>