From a2d50eccb091256ea4358a64bae7f494783a6bca Mon Sep 17 00:00:00 2001 From: Arian Nasr Date: Fri, 6 Mar 2026 05:55:59 -0500 Subject: [PATCH] drag & drop handling --- main.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 72ce4cb..fa75fed 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,6 @@ # Arian Nasr # March 6, 2026 - import os from flask import Flask, request, render_template from werkzeug.utils import secure_filename @@ -20,21 +19,16 @@ def allowed_file(filename): @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': - if 'file' not in request.files: - return render_template('error.html', error_message='No file part in the request'), 400 - files = request.files.getlist('file') - for file in files: - if file.filename == '': - return render_template('error.html', error_message='No selected file'), 400 - if file and allowed_file(file.filename): + for key, file in request.files.items(): + if key.startswith('file') and file and allowed_file(file.filename) and file.filename != '': filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) else: - return render_template('error.html', error_message=f'File "{file.filename}" is not allowed. Allowed types: {", ".join(ALLOWED_EXTENSIONS)}'), 400 + return render_template('error.html', error_message=f'File is not allowed.'), 400 - return render_template('success.html', success_message=f'{len(files)} file(s) uploaded successfully!') + return render_template('success.html', success_message=f'{len(request.files)} file(s) uploaded successfully!'), 200 - return render_template('index.html') + return render_template('index.html'), 200 if __name__ == '__main__':