-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (24 loc) · 767 Bytes
/
main.py
File metadata and controls
29 lines (24 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from uuid import uuid4 as uuid
# python -m pip install redis
from redis import Redis
cache = Redis(host='localhost', port=6379, db=0)
# python -m pip install flask
from flask import Flask, render_template, request
app = Flask(__name__)
@app.get('/')
def index():
return render_template('index.html')
@app.post('/upload')
def upload_post():
id = uuid()
try:
f = request.files['file']
f.save(f'/var/www/uploads/{id}')
cache.set(f'files.{id}.name', f.filename)
cache.set(f'files.{id}.type', f.content_type)
except Exception as e:
return { 'status': 'error', 'message': str(e), 'data': None }
return { 'status': 'ok', 'message': None, 'data': { 'id': id } }
@app.get('/upload')
def upload_get():
return render_template('upload.html')