title: Cant display images from GridFS, PyMongo
body: <p><strong>Hi all</strong>, im a bit new in Python.
  So I have a confused issue for me. I need to store image in database, and after that I have to display each image on client side. Im using Flask for rest request.</p>
  
  <p><strong>So here I have my simpl marckup for submitind</strong></p>
  
  <pre><code>&lt;form action="/upload" method="post" enctype="multipart/form-data"&gt;
      &lt;label for="image"&gt;Select image&lt;/label&gt;
      &lt;input type="file" name='img' id='image'&gt;
      &lt;input type="submit" id='upload_img'&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>and here I get my request and save it to my DB</strong></p>
  
  <pre><code>@app.route("/upload", methods=["POST"])
  def upload_image():
      # get current image file
      img_file = request.files['img']
      # get Content Type and File Name of current image
      content_type = img_file.content_type
      filename = img_file.filename
  
      # save to GridFS my image
      # fields &lt;-- recive the id of just saved image
      fields = db.FS.put(img_file, content_type=content_type, filename=filename)
      # store the filename and _id to another database
      # so here we can much morea easaly get image from our GridFS
      db.Mongo['images'].insert({"filename": filename, "fields": fields})
  
      return index(images=[])
  </code></pre>
  
  <p><strong>My simple database model</strong></p>
  
  <pre><code>class db(object):
     URI = "mongodb://localhost:27017"
     Mongo = None
     FS = None
  
     @staticmethod
     def initialize():
         client = pymongo.MongoClient(db.URI)
         db.Mongo= client['gallery']
         db.FS = GridFS(Database.DATABASE)
  </code></pre>
  
  <p>And all saves is successfully.</p>
  
  <p><strong>Retrive my image from DB and try to send it on clietn</strong></p>
  
  <pre><code>@app.route('/get_all_images')
     def get_image():
     images = db.Mongo['gallery'].find({})
     # try to get just a first image _id and fing it at GridFS files
     image = db.FS.get(images[0]["fields"])
     #send to the client
     return index(images=image.read())
  </code></pre>
  
  <p><strong>Here is markup for display image from the response</strong></p>
  
  <pre><code>    &lt;div&gt;
          &lt;img src="data:image/png;base64,{{images}}" alt=""&gt;
          &lt;div&gt;{{images}}&lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>and finnaly I get something like this <a href="https://i.stack.imgur.com/mPguH.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>the response is look like this:
  <em>b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00w\x00\x00\x00\x7f\x08\x06\x00\x00\x00\xd5j]\xe7\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\xc9e&lt;\x00\x00\x03"iTXtXML:com.adobe.xmp\x00\x00\x00\x00\x00</p>
  
  <p><strong>The problam is</strong> that I cant figute out how to convert this byte format into real image..and display it on a web page directly from database.</p>
  
  <p>I try to make several variants to solve this problam..but in some how my mind is blow up..and I really dont undestand how to work with it.</p>
  
  <p>Thanks for your time :)</em></p>
  
  <p>IF somebady have any idias or advice how can I show images from database into client side...</p>