title: Passing Binary file over HTTP POST
body: <p>I have a local python file that decodes binary files. This python file first reads from the file, opens it as binary and then saves it in a buffer and interprets it. Reading it is simply:</p>
  
  <pre><code>with open(filepath, 'rb') as f:
      buff = f.read()
  read_all(buff)
  </code></pre>
  
  <p>This works fine locally. Now I'd like to setup a Azure Python job where I can send the file, approx. 100kb, over a HTTP POST and then read the interpreted meta data which my original python script does well.</p>
  
  <p>I've first removed the read function so that I'll now work with the buffer only.
  In my Azure Python Job I have the following, triggered by a HttpRequest</p>
  
  <pre><code>my_data = reader.read_file(req.get_body())
  </code></pre>
  
  <p>To test my sending I've tried the following in python</p>
  
  <pre><code>import requests
  
  url = 'http://localhost:7071/api/HttpTrigger'
  files = {'file': open('test', 'rb')}
  with open('test', 'rb') as f:
          buff = f.read()
  
  r = requests.post(url, files=files) #Try using files
  r = requests.post(url, data=buff) #Try using data
  </code></pre>
  
  <p>I've also tried in Postman adding the file to the body as a binary and setting the headers to application/octet-stream</p>
  
  <p>All this doesn't send the binary file the same way as the original f.read() did. So I'm getting a wrong interpretation of the binary file.</p>
  
  <p>What is file.read doing differently to how I'm sending it over as a HTTP Body message?</p>
  
  <p>Printing out the first line from the local python read file gives.</p>
  
  <pre><code>b'\n\n\xfe\xfe\x00\x00\x00\x00\\\x18,A\x18\x00\x00\x00(\x00\x00\x00\x1f\x00\x00\
  </code></pre>
  
  <p>Whereas printing it out at the req.get_body() shows me</p>
  
  <pre><code>b'\n\n\xef\xbf\xbd\xef\xbf\xbd\x00\x00\x00\x00\\\x18,A\x18\x00\x00\x00(\x00\x00\x00\x1f\x00\
  </code></pre>
  
  <p>So something is clearly wrong. Any help why this could be different?</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>I've implemented a similar function in Flask and it works well. 
  The code in flask is simply grabbing the file from a POST. No encoding/decoding.</p>
  
  <pre><code>if request.method == 'POST':
        f = request.files['file']
        #f.save(secure_filename(f.filename))
        my_data = reader.read_file(f.read())
  </code></pre>
  
  <p>Why is the Azure Function different?</p>