title: How to send an image from a Python process to a Flask app with POST request
body: <p>I have</p>
  
  <ul>
  <li><em>takePhoto.py</em> : a Python script that takes a picture from the webcam </li>
  <li><em>app.py</em> a Flask app that handles POST request</li>
  </ul>
  
  <p>How can I send the image taken from <em>takePhoto.py</em> to the Flask app with a POST request? </p>
  
  <p><strong>takePhoto.py</strong></p>
  
  <pre><code>import cv2 
  
  cap = cv2.VideoCapture(0)
  r, f = cap.read()
  
  if r == True: 
      cv2.imwrite("cheese.jpg", f)
      # ---&gt; Here I have the image and I want to send it to the Flask app
  
  cap.release()
  </code></pre>
  
  <p><strong>app.py</strong></p>
  
  <pre><code>import os
  from flask import Flask, render_template, request
  
  app = Flask(__name__)
  IMAGE_FOLDER = os.path.join('static', 'photos')
  app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
  
  
  @app.route('/')
  def show_index():
      return render_template("index.html")
  
  @app.route('/uploadPicture', methods=['POST'])
  def uploadPicture():
      print("uploadPicture function triggered")
      file = request.files['image']
      complete_file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
      file.save(complete_file_path)
      return render_template("gallery.html", current_image = complete_file_path )
  
  if __name__ == ("__main__"):
      app.run()
  </code></pre>