uppy/examples/xhr-python/server.py
Merlijn Vos 7a50ab89ef
Cleanup examples (#5817)
- Remove outdated examples
- Rename folders for consistency
- Remove lots of unused deps in angular example.
- Rename `name` inside `package.json`'s from `@uppy-example/*` to
`example-*`.

**Before**

```
├── angular-example
├── aws-companion
├── aws-nodejs
├── aws-php
├── bundled
├── cdn-example
├── custom-provider
├── digitalocean-spaces
├── multiple-instances
├── node-xhr
├── php-xhr
├── python-xhr
├── react
├── react-native-expo
├── redux
├── sveltekit
├── transloadit
├── transloadit-markdown-bin
├── uppy-with-companion
├── vue3
└── xhr-bundle
```

**After**

```
examples
├── angular
├── aws-companion
├── aws-nodejs
├── aws-php
├── cdn
├── companion
├── companion-custom-provider
├── companion-digitalocean-spaces
├── react
├── react-native-expo
├── redux
├── sveltekit
├── transloadit
├── vue
├── xhr-bundle
├── xhr-node
├── xhr-php
└── xhr-python
```
2025-07-10 17:23:58 +02:00

37 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
import os
from flask import Flask, request, jsonify
from werkzeug.utils import secure_filename
from flask_cors import CORS
UPLOAD_FOLDER = 'uploads'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = os.path.join(os.path.dirname(__file__), UPLOAD_FOLDER)
CORS(app)
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/upload', methods=['POST'])
def upload_file():
if request.method == 'POST':
uploaded_files = request.files.getlist('file')
if not uploaded_files:
return jsonify(error="No files in the request"), 400
uploaded_filenames = []
for file in uploaded_files:
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
uploaded_filenames.append(filename)
if uploaded_filenames:
return jsonify(message="Files uploaded successfully", uploaded_files=uploaded_filenames), 201
else:
return jsonify(error="No valid files uploaded"), 400
if __name__ == '__main__':
app.run(port=3020)