Basic version of eventmedia-management (upload,

save in database)
This commit is contained in:
2025-07-10 09:32:35 +00:00
parent 43306130f7
commit 16581a974f
4 changed files with 23 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
from re import A
from flask import Blueprint, request, jsonify, send_from_directory
from database import Session
from models import EventMedia
from models import EventMedia, MediaType
import os
eventmedia_bp = Blueprint('eventmedia', __name__, url_prefix='/api/eventmedia')
@@ -75,11 +75,26 @@ def filemanager_operations():
@eventmedia_bp.route('/filemanager/upload', methods=['POST'])
def filemanager_upload():
path = request.args.get('path', '/')
session = Session()
# Korrigiert: Erst aus request.form, dann aus request.args lesen
path = request.form.get('path') or request.args.get('path', '/')
upload_path = os.path.join(MEDIA_ROOT, path.lstrip('/'))
os.makedirs(upload_path, exist_ok=True)
for file in request.files.getlist('uploadFiles'):
file.save(os.path.join(upload_path, file.filename))
file_path = os.path.join(upload_path, file.filename)
file.save(file_path)
ext = os.path.splitext(file.filename)[1][1:].lower()
try:
media_type = MediaType(ext)
except ValueError:
media_type = MediaType.other
media = EventMedia(
media_type=media_type,
url=file.filename,
file_path=os.path.relpath(file_path, MEDIA_ROOT)
)
session.add(media)
session.commit()
return jsonify({'success': True})
# --- FileManager: Download ---