Django rest framework response : "The submitted data was not a file. Check the encoding type on the form."

I'm currently testing uploading multiple files(4 images) at once using Postman. Here is how's its configured on Postman.

enter image description here

The key is file_list and the values are the 4 image files I've uploaded to postman. I've configured My Django rest framework view like the following :

class PostImageValidate(APIView):
    permission_classes = (IsAuthenticated, IsNotSuspended)

    def put(self, request):

        request_data = request.data.dict()
        serializer = TempImageSerializer(data=request_data)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data
        file_list = data.get("file_list")
        uploaded_files = data.pop(file_list)

        results = []

        for file in uploaded_files:
            results.append({"filename": file.name, "size": file.size, "status": "Processed})

        return Response({"message": "Images processed successfully", "results": results, "number of items": len(results)}, status=status.HTTP_201_CREATED)
class TempImageSerializer(serializers.Serializer):
    file_list = serializers.ListField(child=serializers.FileField(max_length=150, allow_empty_file=False), allow_empty=False)

However, I get the following response after a span of 5-6 seconds of making a request.

{
    "file_list": {
        "0": [
            "The submitted data was not a file. Check the encoding type on the form."
        ],
        "1": [
            "The submitted data was not a file. Check the encoding type on the form."
        ],
                 }
}
# The key "0" ,"1" extends up to 460 with the same statement above.

I haven't been able to solve the above. My objective is to make sure it returns the Response as expected. Only then I intend to move onto my end of processing those files, the code for which hasn't been inserted.

Вернуться на верх