April 2018
Beginner
340 pages
7h 54m
English
We will need two endpoints to make full use of our avatars – one to upload a new one, and one to fetch an avatar for a particular user.
Open up server.py and add the following functions:
@app.route("/update_avatar/<username>", methods=["POST"])def update_avatar(username): img_b64 = request.form.get("img_b64") database.update_avatar(username, img_b64) return jsonify({ "success": True })
This first endpoint will store the base64 encoded image data in the database against the username provided in the URL:
@app.route("/get_user_avatar/<username>")def get_avatar(username): avatar_b64 = database.get_user_avatar(username)['avatar'] return jsonify({ "avatar": avatar_b64 })
The second endpoint will get the user's base64 encoded ...