title: How can I rename a file in a Python Pyramid Response object?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9991292/how-to-set-file-name-in-response">How to set file name in response</a>  </p>
  </blockquote>
  
  
  
  <p>I store files in MongoDB.  To serve a file from Pyramid, I do this:</p>
  
  <pre><code># view file
  def file(request):
      id = ObjectId(request.matchdict['_id'])
      collection = request.matchdict['collection']
      fs = GridFS(db, collection)
      f = fs.get(id)
      filename, ext = os.path.splitext(f.name)
      ext = ext.strip('.')
      if ext in ['pdf','jpg']:
          response = Response(content_type='application/%s' % ext)
      else:
          response = Response(content_type='application/file')
      response.app_iter = FileIter(f)
      return response
  </code></pre>
  
  <p>Using this method, the filename defaults to the <code>ObjectId</code> string of the file, which isn't pretty and lacks the correct file extension.  I've looked in the docs to see how/where I can rename the file inside the <code>Response</code> object, but I can't see it.  Any help would be fantastic.</p>