check file format in /api/upload/

This commit is contained in:
Joel Mathew Thomas
2025-02-25 23:34:54 +05:30
parent 9bc3a90cf9
commit 2256989fda
+5
View File
@@ -4,6 +4,7 @@ from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from .tasks import save_and_classify
from freqsplit.input.format_checker import is_supported_format
UPLOAD_DIR = "/tmp/freqsplit"
@@ -18,6 +19,10 @@ def upload_audio(request):
audio_file = request.FILES['file']
# Check file format before proceeding
if not is_supported_format(audio_file.name):
return Response({"error": "Unsupported file format"}, status=status.HTTP_400_BAD_REQUEST)
# Generate a unique ID for this upload
file_uuid = str(uuid.uuid4())[:8]