Advertisement
lamiastella

file uploader class version

Oct 13th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. @app.route('/upload', methods=['GET', 'POST'])
  2. @flask_login.login_required
  3. def upload_file():
  4.     if request.method == 'POST':
  5.         uid = getUserIdFromEmail(flask_login.current_user.id)
  6.         imgfile = request.files['photo']
  7.         caption = request.form.get('caption')
  8.         print(caption)
  9.         photo_data = base64.standard_b64encode(imgfile.read())
  10.         cursor = conn.cursor()
  11.         cursor.execute(
  12.             "INSERT INTO Pictures (imgdata, user_id, caption) VALUES ('{0}', '{1}', '{2}' )".format(photo_data, uid,
  13.                                                                                                     caption))
  14.         conn.commit()
  15.         return render_template('hello.html', name=flask_login.current_user.id, message='Photo uploaded!',
  16.                                photos=getUsersPhotos(uid))
  17.     # The method is GET so we return a  HTML form to upload the a photo.
  18.     else:
  19.         return render_template('upload.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement