I'm trying to upload image using django rest framework. But I had a problem with that , when I'm using postman form it upload image successfully, but when I'm trying to type json as row in postman it returns to me this error.
"The submitted data was not a file. Check the encoding type on the form."
here my code:
serializer.py
class UserImageCreateSerializer(serializers.HyperlinkedModelSerializer):
user = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())
class Meta:
model = UserImages
fields = ('user', 'image',)
view.py
class UserImageAPICreateView(ListCreateAPIView):
queryset = UserImage.objects.all()
serializer_class = UserImageCreateSerializer
permission_classes = [AllowAny, AllowAnonymous]
my request:
{
"User": 79,
"image": "/path/to/image.jpg" }
note: when I use postman form it uploaded successfully and when use django rest framework HTML form it works too
I dont know what mistake I did.
so, any one has the solution please help me.