From 2256989fdad04ec343ba43a47d6a91b33fe20e99 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Tue, 25 Feb 2025 23:34:54 +0530 Subject: [PATCH] check file format in /api/upload/ --- api/api/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/api/views.py b/api/api/views.py index 8a993a4..329dc58 100644 --- a/api/api/views.py +++ b/api/api/views.py @@ -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]