Example #1
0
def upload():
    # check if the post request has the file part
    if 'file' not in request.files:
        flash('No file part')
        return redirect('/library')
    file = request.files['file']

    # if user does not select file, browser also
    # submit an empty part without filename
    if file.filename == '':
        flash('No selected file')
        return redirect('/library')
    if file and allowed_photo_filename(file.filename):
        new_photo = Photo(user_id=session['user_id'])
        db.session.add(new_photo)
        db.session.flush()

        filename = f'{new_photo.photo_id}_{secure_filename(file.filename)}'
        s3.upload(file, filename)

        new_photo.original_photo = filename
        db.session.commit()

        return redirect(f'/processing/{new_photo.photo_id}')