title: How to receive an image from a POST request on Google Cloud Function with Python?
body: <p>I'm struggling to reassemble an image sent via a POST request to a GCP Cloud Function.</p>
  <p>I've looked at advice <a href="https://stackoverflow.com/a/22974646/11118905">here</a> about how to package a file with POST request.</p>
  <p>I would like the function to reconstruct the image from bytes for further processing, everytime I send the request I get 'Failure' back. Any help would be really appreciated!</p>
  <pre class="lang-py prettyprint-override"><code>### client_side.py
  import requests
  
  url = 'https://region-project.cloudfunctions.net/function' # Generic GCP functions URL
  files = {'file': ('my_image.jpg', open('my_image.jpg', 'rb').read(), 'application/octet-stream')}
  r = requests.post(url, files=files)
  
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>### gcp_function.py
  from io import BytesIO
  
  def handler(request):
      try:
          incoming = request.files.get('file')
          bytes = BytesIO(incoming)
          image = open_image(bytes)
          message = 'Success'
      except:
          message = 'Failure'
      return message
  
  </code></pre>