title: Django: Uploading a file to a REST API with a FileField in a model
body: <p>So here is the context. I am using Django with Python3.6, and we're using Django REST Framework to build our REST API. I have a simple form on a page, but it is not submitted directly. I am calling manually our API using axios.</p>
  
  <p>Here's the code used when pressing the submit button:</p>
  
  <pre><code>let form = new FormData();
  form.append('name', this.game.name);
  form.append('video', this.game.video);
  form.append('icon', this.game.icon);
  
  axios.post("api/games/", form, {headers: {
      'Content-Type': 'multipart/form-data',
  }})
  </code></pre>
  
  <p>Everything is fine here. My API receive the correct data, I can create my game object easily.</p>
  
  <p>The main issue is the 'video' field. It is registered as a FileField in my models.py</p>
  
  <pre><code>name = models.CharField(max_length=255, unique=True)
  icon = models.ImageField(upload_to=user_directory_path)
  video = models.FileField(upload_to=user_directory_path)
  </code></pre>
  
  <p>When submitting an MP4 video file (.mp4) that is like 500ko, it is working properly.</p>
  
  <p>But when I try to upload a file that is much greater, like 5 mo and with format QT (.mov), I got an error from django:</p>
  
  <pre><code>ERROR 2017-11-23 16:59:31,831 exception Internal Server Error: /api/games/
  Traceback (most recent call last):
    File "myawesomeproject/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "myawesomeproject/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "myawesomeproject/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "myawesomeproject/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
      return view_func(*args, **kwargs)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/viewsets.py", line 90, in view
      return self.dispatch(request, *args, **kwargs)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
      response = self.handle_exception(exc)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
      self.raise_uncaught_exception(exc)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
      response = handler(request, *args, **kwargs)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/mixins.py", line 21, in create
      self.perform_create(serializer)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/mixins.py", line 26, in perform_create
      serializer.save()
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/serializers.py", line 214, in save
      self.instance = self.create(validated_data)
    File "myawesomeproject/api/serializers.py", line 114, in create
      return super().create(validated_data)
    File "myawesomeproject/lib/python3.6/site-packages/rest_framework/serializers.py", line 913, in create
      instance = ModelClass.objects.create(**validated_data)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
      return getattr(self.get_queryset(), name)(*args, **kwargs)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/query.py", line 394, in create
      obj.save(force_insert=True, using=self.db)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/base.py", line 808, in save
      force_update=force_update, update_fields=update_fields)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/base.py", line 838, in save_base
      updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/base.py", line 924, in _save_table
      result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/base.py", line 963, in _do_insert
      using=using, raw=raw)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
      return getattr(self.get_queryset(), name)(*args, **kwargs)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/query.py", line 1076, in _insert
      return query.get_compiler(using=using).execute_sql(return_id)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1106, in execute_sql
      for sql, params in self.as_sql():
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1059, in as_sql
      for obj in self.query.objs
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1059, in &lt;listcomp&gt;
      for obj in self.query.objs
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1058, in &lt;listcomp&gt;
      [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1008, in pre_save_val
      return field.pre_save(obj, add=True)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/fields/files.py", line 296, in pre_save
      file.save(file.name, file.file, save=False)
    File "myawesomeproject/lib/python3.6/site-packages/django/db/models/fields/files.py", line 94, in save
      self.name = self.storage.save(name, content, max_length=self.field.max_length)
    File "myawesomeproject/lib/python3.6/site-packages/django/core/files/storage.py", line 54, in save
      return self._save(name, content)
    File "myawesomeproject/lib/python3.6/site-packages/django/core/files/storage.py", line 338, in _save
      file_move_safe(content.temporary_file_path(), full_path)
    File "myawesomeproject/lib/python3.6/site-packages/django/core/files/move.py", line 58, in file_move_safe
      with open(old_file_name, 'rb') as old_file:
  FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/wc/6cny2lg147l55mt4zm92zw9m0000gn/T/tmp6xuujgz2.upload'
  </code></pre>
  
  <p>I read online that Django is handling files differently depending on their size which leads me to believe that it comes from that.</p>
  
  <p>But besides some information, I couldn't find any solutions to my problem.</p>
  
  <p>Is there something I am doing wrong here?</p>