title: How to fix ImageField upload in django rest framework?
body: <p>I am trying to upload a profile image to the media folder, while this works perfectly from the django admin web interface, it doesn't upload from the api endpoint, it gives the media root with image name, but i cannot access the image nor is it in the location pointed to by the get_upload_path method. Any help would be greatly appreciated.</p>
  
  <p><strong>settings.py:</strong></p>
  
  <p><code>MEDIA_URL = '/media/'
   MEDIA_ROOT = os.path.join(BASE_DIR, "media")</code></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>model:</strong> </p>
  
  <p><code>def get_upload_path(instance, filename):
      return 'grey/{0}/{1}'.format(instance.category_name, filename)</code></p>
  
  <p><code>class Category(models.Model):
  icon_url_greyscale = models.ImageField(
          upload_to=get_upload_path, null=True, blank=True)</code></p>
  
  <p><strong>serializer.py:</strong></p>
  
  <p><code>class CategoryCreateSerializer(serializers.ModelSerializer):
  def create(self, validated_data):
  cat = Category.objects.create(**validated_data)</code></p>
  
  <p><strong>views.py:</strong></p>
  
  <p><code>class CategoryCreateAPIView(APIView):
      permission_classes = (IsAdminUser,)
      serializer_class = CategoryCreateSerializer</code></p>
  
  <pre><code>`def post(self, request):
      data = request.data
      print(data)
      serializer = self.serializer_class(data=data)
      if serializer.is_valid():
          serializer.save()
          return Response({'status':True, 'message':'category created'}, status=status.HTTP_201_CREATED)
      else:
          raise CustomException(detail="Could not create category", status_code=status.HTTP_400_BAD_REQUEST)`
  </code></pre>
  
  <p>This is expected result:
  '"<a href="http://127.0.0.1:8000/media/profile_photo/aafaaaaaa2a%40gmail.com/lol.jpg" rel="nofollow noreferrer">http://127.0.0.1:8000/media/profile_photo/aafaaaaaa2a%40gmail.com/lol.jpg</a>"'</p>
  
  <p>This is what am getting:</p>
  
  <p>"<a href="http://127.0.0.1:8000/media/test.jpg" rel="nofollow noreferrer">http://127.0.0.1:8000/media/test.jpg</a>"</p>