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)