I'm a newbie to the Flask and trying to load a image which stored in my database type of Binary like this:
avatar_local = db.Column(db.LargeBinary(1024*1024))
now how to show it in a html file?
this is my file and it can't work correctly:
<img class="img-rounded profile-thumbnail" src="{{ user.avatar_local }}">
I got wrong message:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
This is my upload function, it works fine:
@main.route('/upload', methods=['GET', 'POST'])
def upload_avatar():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
current_user.avatar_local = file.read()
db.session.add(current_user)
db.session.commit()
return redirect(url_for('main.user_page', username=current_user.username))
return render_template('upload_avatar.html', user=current_user)