title: How to render image from Flask-SQLAlchemy on page?
body: <p>I'm trying to render image on my website but it's doesn't work (i see only corrupted file icon). Could You please tell me what i'm doing wrong ? </p>
  
  <p>The way how I upload the image:</p>
  
  <pre><code>@app.route('/UploadImages')
  def UploadImages():
      return render_template('UploadImages.html')
  
  
  @app.route('/uploadImages', methods=['POST'])
  def uploadImages():
      name = current_user.USERNAME
      file = request.files['inputFile']
      newFile=IMAGES(
          NAME=file.filename,
          USERNAME=name,
          DATA=file.read()
      )
      db.session.add(newFile)
      db.session.commit()
  
      return 'Saved ' + file.filename + 'to the database !'
  </code></pre>
  
  <p>Here is my db table:</p>
  
  <pre><code>class IMAGES(db.Model):
      ID = db.Column(db.Integer,primary_key=True)
      NAME = db.Column(db.String(300),unique=True)
      DATA = db.Column(db.BLOB)
      USERNAME = db.Column(db.String(15))
  </code></pre>
  
  <p>I'm sure that the file is upload correctly because when I use:</p>
  
  <pre><code>@app.route('/download')
  def download():
      file_data = IMAGES.query.filter_by(USERNAME='test1').first()
  
      return send_file(BytesIO(file_data.DATA),
  attachment_filename='test.jpg',as_attachment=True) 
  </code></pre>
  
  <p>I get the image not corrupted.</p>
  
  <p>How I try to render the file: </p>
  
  <pre><code>@app.route('/image')
  def image():
      file_data = IMAGES.query.filter_by(USERNAME='test1').first()
      image = b64encode(file_data.DATA)
      return render_template('Image.html',data=list,image=image)
  </code></pre>
  
  <p>and on the website:</p>
  
  <pre><code>&lt;img src="data:;b64encode,{{ image }}"/&gt;
  </code></pre>