'Error: Invalid data. Expected a dictionary, but got InMemoryUploadedFile
I am getting the above error when trying to upload multiple pictures from react to django rest api. This is my django view code:
def post(self, request, *args, **kwargs):
posts_serializer = PostSerializer(data=request.FILES.getlist('image[]'), many=True)
print(posts_serializer)
if posts_serializer.is_valid():
posts_serializer.save()
return Response(posts_serializer.data, status=status.HTTP_201_CREATED)
else:
print('error', posts_serializer.errors)
return Response(posts_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
This is a print from posts_serializer:
PostSerializer(data=[<InMemoryUploadedFile: 1PSM Logo.png (image/png)>, <InMemoryUploadedFile: Microsoft-Azure-Fundamentals.png (image/png)>, <InMemoryUploadedFile: DP-900_ProductImage-1.png (image/png)>], many=True):
id = IntegerField(label='ID', read_only=True)
image = ImageField(max_length=100)
Appreciate any help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
