'DRF serializer does not send the correct data from the request

I build an API endpoint that talks an image as input and print it on the screen, the problem is when I print the request.data it gives me the correct data, but when I pass this data to the serializer, DRF change it!


serializer:

class TestUploadImageSerializer(serializers.Serializer):
     images = serializers.ImageField()
     other_data = serializers.CharField(max_length=255)

views:

class TestUploadImageApi(APIView):

    def post(self, request):
        serializer = TestUploadImageSerializer(data=request.data)

        serializer.is_valid(raise_exception=True)
    
        print(f'request.data =  {request.data} \n')
        print(f'serializer.data =  {serializer.data} \n')

        return Response(status=status.HTTP_200_OK)

I'm using Postman to send the image:

enter image description here


This is the output for request.data and serializer.data

request.data =  <QueryDict: {'other_data': ['Test API'], 'images': [<InMemoryUploadedFile: ikea3.png (image/png)>]}> 

serializer.data =  {'images': None, 'other_data': 'Test API'} 

So, the question is why serializer.data gives me these result?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source