check file format in /api/upload/
This commit is contained in:
@@ -4,6 +4,7 @@ from rest_framework.decorators import api_view
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from .tasks import save_and_classify
|
from .tasks import save_and_classify
|
||||||
|
from freqsplit.input.format_checker import is_supported_format
|
||||||
|
|
||||||
UPLOAD_DIR = "/tmp/freqsplit"
|
UPLOAD_DIR = "/tmp/freqsplit"
|
||||||
|
|
||||||
@@ -18,6 +19,10 @@ def upload_audio(request):
|
|||||||
|
|
||||||
audio_file = request.FILES['file']
|
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
|
# Generate a unique ID for this upload
|
||||||
file_uuid = str(uuid.uuid4())[:8]
|
file_uuid = str(uuid.uuid4())[:8]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user