drf

89 views
Skip to first unread message

NAOUI YACINE

unread,
Jan 4, 2024, 3:34:56 PMJan 4
to Django REST framework
this a apiview to upload files , i don't know where is the mistake 
class Article_upload(APIView):
parser_classes = (FileUploadParser,)
def post(self, request, *args, **kwargs):
file_obj = request.FILES.get('file')

if file_obj is None:
return Response({'error': 'No file found in the request'}, status=status.HTTP_400_BAD_REQUEST)

if not file_obj.name.endswith('.pdf'):
return Response({'error': 'File must be a PDF'}, status=status.HTTP_400_BAD_REQUEST)

# Process the uploaded PDF file as needed (e.g., save to disk, extract information, etc.)
# In this example, we are just returning the file name in the response.
return Response({'filename': file_obj.name}, status=status.HTTP_201_CREATED)
Reply all
Reply to author
Forward
0 new messages