Search code examples
djangofilefield

Avoid copying when adding a large file to FileField


I'm dealing with some quite large files which are uncomfortable to upload via http, so my users upload files using FTP which my code then needs to move into FileField.upload_to (where they normally end up when uploaded via HTTP). My problem is, the commonly suggested method of using django.core.files.File:

from django.core.files import File

# filename is a FileField
file_obj = MyModel(filename=File(open('VIDEO_TS.tar', 'rb')))

leads to copying the data, which i need to avoid. Is there any way to add the already existing file to a FileField while making sure upload_to is called?


Solution

  • I'd say that easiest way would be writing your own field or storage.