[Python] I'm having difficulty uploading a video into the static folder of my flask app 413...

Discussão em 'Python' iniciado por Stack, Março 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using the basic port 5000 development server. I'm trying to make a training portal for a cafe for my final project in cs50. The cafe wanted the ability to upload and delete training by management within the portal so that training can remain up to date. I've hit a wall as far as uploading videos

    I configured the flask app to accept up to 1.8GB and made the route to handle any number of questions, answers, and options related to the video being uploaded

    app=Flask(__name__)

    # Set the maximum allowed request size to 1.8 GB
    app.config["MAX_CONTENT_LENGTH"] = 1.8 * 1024 * 1024 * 1024 # 1.8 GB in bytes


    @app.route("/trainingupload", methods=["GET", "POST"])
    @login_required
    def trainingupload():
    """upload training"""
    """only for management"""
    if request.method == 'POST':
    file = request.files['video']
    questions=request.form.getlist("question[]")
    answers=request.form.getlist("answer[]")
    secondary_options=request.form.getlist("option2[]")
    tertiary_options=request.form.getlist("option3[]")
    quarternary_options=request.form.getlist("option4[]")
    n=len(quarternary_options)
    if not(len(questions)==n and len(answers)==n and len(secondary_options)==n and len(tertiary_options)==n):
    return error("missing one or more fields", language=language)
    elif not (file and allowed_videos(file.filename)):
    return error("incorrect video format", language=language )
    elif not request.form.get("position"):
    return error("no position added", language=language)
    elif file and allowed_videos(file.filename):
    filename = secure_filename(file.filename)
    # Save the file path in a variable
    video_path = os.path.join(VIDEO_FOLDER, filename)
    # Save the file to the specified path
    file.save(video_path)
    position=request.form.get("position")
    db.execute("insert into training_key (video_path, require) values(?, ?)", video_path, position)
    training_id=db.execute("select training_id from training_key where require=? and video_path=?", position, video_path)[0]["training_id"]
    flash(f"Video uploaded successfully: {filename}")
    for i in range(n):
    db.execute("insert into quiz (training_id, question, answer, option2, option3, option4) values(?, ?, ?, ?, ?, ?)",
    training_id, questions, answers, secondary_options, tertiary_options, quarternary_options
    )
    return render_template('training_upload.html')
    else:
    return render_template('training_upload.html')


    I managed to upload a four second video without issue but then I tried a fourteen second video and it gave the error.

    <label for="video">Choose a Video File to Upload 'mp4', 'mkv', or 'avi' only: </label>
    <input style="background-color: #fdfdfd;" type="file" name="video" id="video" accept="video/*" required>


    I need to be able to upload a nine minute video at 30fps in 1080p which I researched to be 1.8GB max. Any help leading to a resolution of this error would be greatly appreciated.

    Continue reading...

Compartilhe esta Página