title: Django Rest Framework : Upload Image API
body: <p>I am trying to upload image to my django website through django rest framework api.
  but I am getting this error</p>
  
  <blockquote>
    <p>{
        "detail": "Multipart form parse error - Invalid boundary in multipart: None" }</p>
  </blockquote>
  
  <p>views.py</p>
  
  <pre><code>class UploadPhotoViewSet(APIView):
      parser_classes = (parsers.MultiPartParser, parsers.FormParser)
  
      def get(self, request,  format=None):
          model_object = Photo.objects.all()
          serializer = PhotoSerializer(model_object, many=True)
          return Response(serializer.data)
  
      def post(self, request, format=None):
          serializer = PhotoSerializer(data=request.data)
  
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>serializers.py</p>
  
  <pre><code>class PhotoSerializer(serializers.ModelSerializer):
      thumbnail = serializers.ImageField(use_url=True)
      source = serializers.ImageField(use_url=True)
      class Meta:
          model = Photo
          fields = '__all__'
  </code></pre>
  
  <p>model.py</p>
  
  <pre><code>class Photo(models.Model):
      type = models.CharField(max_length=100, default='photo', editable=False)
      project = models.ForeignKey(Project, on_delete=models.CASCADE)
      title = models.CharField(max_length=100)
      description = models.TextField()
      category = models.CharField(max_length=255)
  
      def upload_thumb_dir(self, filename):
          path = '/media/{}/photos/thumbs/{}'.format(self.project.id, filename)
          return path
      thumbnail = models.ImageField(upload_to=upload_thumb_dir, default='/default/photo.png', blank=True)
  
      def upload_photo_dir(self, filename):
          path = '/media/{}/photos/{}'.format(self.project.id, filename)
          return path
      source = models.ImageField(upload_to=upload_photo_dir)
  
      def __str__(self):
          return self.title
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eBfCj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eBfCj.png" alt="enter image description here"></a></p>