title: Because PIL expects a file object, I'm trying to use tempfile to create a file. Running into what I think are buffer problems
body: <p>I'm trying to create a temporary file from an entry in my database. I have done a <code>print(filedata['data'])</code> and I can see that the data is being retrieved properly but even with the <code>temp_h.flush()</code> I never see any data saved to the file. When I go to retrieve it, the file is empty. Could someone please explain to me what's causing this and if there's a better way to do what I'm trying to do with PIL, I'd love to learn that too. I'm running this on a Linux system with an EXT3 File system</p>
  
  <pre><code>def main():
      '''Main'''
  
      for nohisto in thestash.stash.get_files():
         fileid = str(nohisto['_id'])
         filedata = openstash(fileid)
         temp_h = tempfile.TemporaryFile(mode='r+')
         temp_h.write(filedata['data'])
         temp_h.flush()
         time.sleep(3)
         myhisto = Image.open(temp_h).histogram()
  </code></pre>