title: Flask to return image stored in database
body: <p>My images are stored in a MongoDB, and I'd like to return them to the client,  here is how the code is like:</p>
  
  <pre><code>@app.route("/images/&lt;int:pid&gt;.jpg")
  def getImage(pid):
      # get image binary from MongoDB, which is bson.Binary type
      return image_binary
  </code></pre>
  
  <p>However, it seems that I can't return binary directly in Flask? My idea so far:</p>
  
  <ol>
  <li>Return the <code>base64</code> of the image binary. The problem is that IE&lt;8 doesn't support this.</li>
  <li>Create a temporary file then return it with <code>send_file</code>.</li>
  </ol>
  
  <p>Are there better solutions?</p>