title: Unable to populate request.files in flask through okhttp
body: <p>I am sending an image from imageView to flask server after conversion but the request.files is empty.
  code:</p>
  <pre><code>public void onFindCountButtonClicked(View view){
          String postUrl = &quot;http://192.168.x.x:5000/&quot;;
          ImageView originalImage = findViewById(R.id.originalImage);
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap = ((BitmapDrawable) originalImage.getDrawable()).getBitmap();
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
          byte[] byteArray = stream.toByteArray();
          RequestBody postBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
                  .addFormDataPart(&quot;image&quot;, &quot;androidFlask.jpg&quot;, RequestBody.create(MediaType.parse(&quot;image/*jpg&quot;), byteArray)).build();
          postRequest(postUrl, postBody);
      }
  
  
  private void postRequest(String postUrl, RequestBody postBodyText) {
          OkHttpClient client = new OkHttpClient();
          Request request = new Request.Builder().url(postUrl).post(postBodyText).build();
          client.newCall(request).enqueue(new Callback() {
              @Override
              public void onFailure(Call call, IOException e) {
                  call.cancel();
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          TextView textView = findViewById(R.id.txtCount);
                          textView.setText(&quot;Connection failed&quot;);
                          densityMap = findViewById(R.id.densityMap);
                          densityMap.setImageBitmap(bitmap);
                      }
                  });
              }
  
              @Override
              public void onResponse(Call call, final Response response) throws IOException {
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          TextView responseText = findViewById(R.id.txtCount);
                          try {
                              responseText.setText(response.body().string());
                          } catch (IOException e){
                              e.printStackTrace();
                          }
                      }
                  });
              }
          });
      }
  </code></pre>
  <p>Flask Code:</p>
  <pre><code>
  import os
  from flask import Flask, render_template, request, redirect, url_for
  from werkzeug.utils import secure_filename
  
  UPLOAD_FOLDER = './static/'
  ALLOWED_EXTENSIONS = set(['.jpg', '.jpeg'])
  
  app = Flask(__name__)
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  
  @app.route('/', methods=['GET', 'POST'])
  def upload_file():
      if request.method == 'POST':
          # Remove existing images in directory
          files_in_dir = os.listdir(app.config['UPLOAD_FOLDER'])
          filtered_files = [file for file in files_in_dir if file.endswith(&quot;.jpg&quot;) or file.endswith(&quot;.jpeg&quot;)]
          for file in filtered_files:
              path = os.path.join(app.config['UPLOAD_FOLDER'], file)
              os.remove(path)
  
          # Upload new file
          if 'file' not in request.files:
              return redirect(request.url)
          file = request.files['file']
          filename = secure_filename(file.filename)
          file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
          return &quot;success&quot; 
      return &quot;failed&quot;
  
  
  if __name__ == '__main__':
      app.run(debug=True, host='0.0.0.0', threaded=True)
  </code></pre>
  <p>I keep on getting 'failed'. If I remove the if statement for the request files, I get this error: ine 442, in <strong>getitem</strong>
  raise exceptions.BadRequestKeyError(key)
  werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
  KeyError: 'file'</p>