Skip to content

Instantly share code, notes, and snippets.

@satomacoto satomacoto/sample.py
Created May 12, 2019

Embed
What would you like to do?
copy django FileFiled object to tempfile
import shutil
import tempfile
from app.models import Record
# %%
%%time
with tempfile.NamedTemporaryFile() as tmp:
record = Record.objects.first()
tmp.write(record.datafile.read())
# %%
%%time
with tempfile.NamedTemporaryFile() as tmp:
record = Record.objects.first()
with record.datafile.open() as src:
shutil.copyfileobj(src, tmp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.