Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/upload', methods=['GET', 'POST'])
- @flask_login.login_required
- def upload_file():
- if request.method == 'POST':
- uid = getUserIdFromEmail(flask_login.current_user.id)
- imgfile = request.files['photo']
- caption = request.form.get('caption')
- print(caption)
- photo_data = base64.standard_b64encode(imgfile.read())
- cursor = conn.cursor()
- cursor.execute(
- "INSERT INTO Pictures (imgdata, user_id, caption) VALUES ('{0}', '{1}', '{2}' )".format(photo_data, uid,
- caption))
- conn.commit()
- return render_template('hello.html', name=flask_login.current_user.id, message='Photo uploaded!',
- photos=getUsersPhotos(uid))
- # The method is GET so we return a HTML form to upload the a photo.
- else:
- return render_template('upload.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement