Re: What's the best way to save generated images?

25 views
Skip to first unread message

JC Briar

unread,
Sep 25, 2012, 12:03:21 PM9/25/12
to django...@googlegroups.com
Okay, this may not be the most efficient implementation, but it works:

  # create temporary file
  tmpfile = tempfile.TemporaryFile()
  write to tmpfile

  # wrap temporary file with django.core.files.File
  fileContents = django.core.files.File(tmpfile)
  fileContents.size = tmpfile.tell()  # admittedly, a bit of a hack
 
  # create and save new Model
  model = Chart(**kwargs)
  model.image.save(fn, fileContents)
Reply all
Reply to author
Forward
0 new messages