I'm am one of the authors of the 2070 patch [1]. Indeed, it is what
will help you here.
However, I'm not sure how it will work with your code as I don't
really see the context and I'm not omniscient. However, here's how
you'd write to files in #2070::
from django.core.files.filemove import file_move_safe
file_obj = request.FILES['field_name']
if hasattr(file, 'temporary_file_path'):
file_obj.close()
file_move_safe(file_obj.temporary_file_path(),
destination_path)
else:
# We use file locks because with such large files collisions
*do* happen.
from django.core.files import filelocks
fp = open(destination_path, 'wb')
filelocks.lock(fp, filelocks.LOCK_EX)
for chunk in file_obj.chunk():
fp.write(chunk)
filelocks.unlock(fp)
fp.close()
Note that most of this code is in _save_FIELD_file in
django.db.models.base after patching #2070.
Also note that if you use the standard save_field_file interface, this
is already done for you. So you can write::
instance = SomeModel(...)
instance.save_field_file(request.FILES['field_name'].file_name,
request.FILES['field_name'], save=False)
instance.save()
And it will do what I outlined above.
I hope this helps! Let me know if you have any problems or further
questions. (Specifically, posting in #2070 will let me keep track of
it better.)
Cheers,
Mike
1:
http://code.djangoproject.com/ticket/2070