Performance: File upload forms
MEDIUM IMPACT
This affects page load speed and interaction responsiveness when users upload files through forms.
from flask import Flask, request app = Flask(__name__) @app.route('/upload', methods=['POST']) def upload(): file = request.files['file'] with open('/tmp/' + file.filename, 'wb') as f: while chunk := file.stream.read(4096): f.write(chunk) return 'File uploaded!'
from flask import Flask, request app = Flask(__name__) @app.route('/upload', methods=['POST']) def upload(): file = request.files['file'] data = file.read() with open('/tmp/' + file.filename, 'wb') as f: f.write(data) return 'File uploaded!'
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Loading full file into memory | Minimal | 0 | Low | [X] Bad |
| Streaming file in chunks | Minimal | 0 | Low | [OK] Good |