title: Uploading a photo using XMLHtttpRequest to a Flask webserver
body: <p>I'm creating a WinJS app and using XMLHttpRequest to send a photo as a blob to a Flask webserver.</p>
  
  <pre><code>openPicker.pickSingleFileAsync().then(function (file) {
          file.openAsync(Windows.Storage.FileAccessMode.read).done(function (stream) {
              var blob = MSApp.createBlobFromRandomAccessStream("application/octet-stream", stream);
              var fdata = new FormData();
              fdata.append("file", blob, "photo.jpg");
  
              var xmlhttp = new XMLHttpRequest();
              xmlhttp.open("POST", "http://127.0.0.1:5000/api/addPhoto", true);
              xmlhttp.setRequestHeader("Content-type", "multipart/form-data");
              xmlhttp.send(fdata);
          });
      });
  </code></pre>
  
  <p>This results in the following HTTP request:</p>
  
  <pre><code>POST http://127.0.0.1:5000/api/addPhoto HTTP/1.1
  Accept: */*
  Content-Type: application/octet-stream, multipart/form-data; boundary=---------------------------7dd2a320aa0ec0
  Accept-Language: en-US,en;q=0.7,ja;q=0.3
  UA-CPU: AMD64
  Accept-Encoding: gzip, deflate
  User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; MSAppHost/1.0)
  Host: 127.0.0.1:5000
  Content-Length: 9471100
  Connection: Keep-Alive
  Pragma: no-cache
  
  -----------------------------7dd2a320aa0ec0
  Content-Disposition: form-data; name="file"; filename="photo.jpg"
  Content-Type: application/octet-stream
  </code></pre>
  
  <p>Handling the request on the Flask web server</p>
  
  <pre><code>UPLOAD_FOLDER = '/images'
  @app.route('/api/addPhoto', methods=['POST'])
  def addPhoto():
          if request.method == 'POST':
              f = request.files['file']
              if f and allowed_file(f.filename):
                      return "error" #add error response here
          else:
                      filename = secure_filename(f.filename)
                      f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                      f.close
                      return "ok" #add success response here
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>TypeError: 'ImmutableMultiDict' object is not callable
  </code></pre>
  
  <p>I have a few questions that I can't find answers for:</p>
  
  <ul>
  <li>Am I sending the data in the right format? Am I appending data to my form correctly?</li>
  <li>Are my HTTP content types correct?</li>
  <li>Am I trying to pull the file from the HTTP request incorrectly?</li>
  </ul>
  
  <p>Thank you!</p>