title: How To Upload File with Django Rest APi
body: <p>can someone help me how to upload file with POST method in django rest api, 
  for example when I launch </p>
  
  <pre><code>curl -X POST 127.0.0.1:8000/api/v1/assets/ -d '{"name" = "my image   ","source"="/root/images/my_image2.jpg"}' -H "Content-Type: application/json"
  </code></pre>
  
  <p>I want to upload my_image2.jpg </p>
  
  <p>serializers.py:</p>
  
  <pre><code>from django.forms import widgets
  from rest_framework import serializers
  from .models import Asset
  
  class AssetSerializer(serializers.ModelSerializer):
      class Meta:
          model = Asset
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>from .serializers import AssetSerializer
  from django.http import Http404
  from rest_framework.views import APIView
  from rest_framework.response import Response
  from rest_framework import status
  
  from rest_framework import status
  from rest_framework.decorators import api_view
  
  
  class AssetAdd(APIView):
  
  
      def post(self, request, format=None):
          serializer = AssetSerializer(data=request.DATA)
          print serializer.data
  
          if serializer.is_valid():
  
              serializer.save()
              return Response(serializer.data, status=status.HTTP_201_CREATED)
  
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>models.py </p>
  
  <pre><code>class Asset(models.Model):
  
      key = models.CharField(max_length=8, unique=True, editable=False)
      name = models.CharField(_('name'), max_length=200)
      source = models.FileField(_('file'), upload_to=upload_to, storage=default_storage)
  
      ext = models.CharField(max_length=15, editable=False)
      type = models.PositiveIntegerField(choices=ASSET_TYPE, max_length=15, editable=False)
      size = models.PositiveIntegerField(max_length=32, default=0, editable=False)
  
      _file_meta = models.TextField(editable=False, null=True, blank=True)
  
      public = models.BooleanField(default=False)
      position = models.PositiveIntegerField(default=1)
  
      object_id = models.PositiveIntegerField(default=1)
      content_type = models.ForeignKey(ContentType, blank=True, null=True)
      content_object = generic.GenericForeignKey('content_type', 'object_id')
  
      created = models.DateTimeField(auto_now_add=True)
      modified = models.DateTimeField(auto_now_add=True, auto_now=True)
  </code></pre>
  
  <p>I'm newbie in Django REST API , I read documentation  <a href="http://www.django-rest-framework.org/api-guide/parsers.html#fileuploadparser" rel="noreferrer">http://www.django-rest-framework.org/api-guide/parsers.html#fileuploadparser</a> , but still don't undestand how to do it </p>