title: How to use images from Azure Functions Blob Trigger with Form Recognizer
body: <p>I am trying to use Azure Functions to wrap an application using Form-Recognizer written in Python. My issue is getting a JPEG using the BlobTrigger into a format that the Form-Recognizer can work with. </p>
  
  <p>The basic code for opening the image is </p>
  
  <pre class="lang-py prettyprint-override"><code>from PIL import Image
  from io import BytesIO 
  import azure.functions as func
  
  def main(blobin: func.InputStream, blobout: func.Out[bytes], context: func.Context):
  image = Image.open(blobin)
  </code></pre>
  
  <p>The image has class class: 'PIL.JpegImagePlugin.JpegImageFile'.</p>
  
  <p>The code for calling the Form-Recognizer analyze is as follows:</p>
  
  <pre class="lang-py prettyprint-override"><code>base_url = r"&lt;url&gt;" + "/formrecognizer/v1.0-preview/custom"
  model_id = "&lt;model-id&gt;"
  headers = {
      'Content-Type': 'image/jpeg',
       'Ocp-Apim-Subscription-Key': '&lt;subscription-key&gt;',
  }
  resp = None
  try:
      url = base_url + "/models/" + model_id + "/analyze" 
      resp = http_post(url = url, data = image, headers = headers)
      print("Response status code: %d" % resp.status_code)    
  except Exception as e:
      print(str(e))
  </code></pre>
  
  <p>Unfortunately, the data = image in the http_post needs to be class: 'bytes'.</p>
  
  <p>So, I tried various ways using PIL to convert the input image to a byte format.</p>
  
  <p>My two main approaches were </p>
  
  <pre class="lang-py prettyprint-override"><code>with BytesIO() as output:
      with Image.open(input_image) as img:
      img.save(output, 'JPEG')
      image = output.getvalue()
  </code></pre>
  
  <p>and</p>
  
  <pre class="lang-py prettyprint-override"><code>image = Image.open(input_image)
  imgByteArr = io.BytesIO()
  image.save(imgByteArr, format='JPEG')
  imgByteArr = imgByteArr.getvalue()
  </code></pre>
  
  <p>Both of these approaches give me a byte format, however, it still doesn't work. Either way, I end up with this response: </p>
  
  <pre><code>{'error': {'code': '2018', 'innerError': {'requestId': '8cff8e76-c11a-4893-8b5d-33d11f7e7646'}, 'message': 'Content parsing error.'}}
  </code></pre>
  
  <p>Does anyone know the right way to approach this problem?</p>