title: App Engine - download files from Cloud Storage
body: <p>I am using Python 2.7 and Reportlab to create .pdf files for display/print in my app engine system. I am using ndb.Model to store the data if that matters.</p>
  
  <p>I am able to produce the equivalent of a bank statement for a single client on-line. That is; the user clicks the on-screen 'pdf' button and the .pdf statement appears on screen in a new tab, exactly as it should.</p>
  
  <p>I am using the following code to save .pdf files to Google Cloud Storage successfully</p>
  
  <pre><code>buffer = StringIO.StringIO()
  self.p = canvas.Canvas(buffer, pagesize=portrait(A4))
  self.p.setLineWidth(0.5)
  
  try:
  
      # create .pdf of .csv data here
  
  finally:
      self.p.save()
      pdfout = buffer.getvalue()
      buffer.close()
  
      filename = getgcsbucket() + '/InvestorStatement.pdf'  
      write_retry_params = gcs.RetryParams(backoff_factor=1.1)
  
      try:
          gcs_file = gcs.open(filename,
                              'w',
                              content_type='application/pdf',
                              retry_params=write_retry_params)
          gcs_file.write(pdfout)
      except:
          logging.error(traceback.format_exc())
      finally:
          gcs_file.close()
  </code></pre>
  
  <p>I am using the following code to create a list of all files for display on-screen, it shows all the files stored above.</p>
  
  <pre><code>allfiles = []
  
  bucket_name = getgcsbucket()
  
  rfiles = gcs.listbucket(bucket_name)
  for rfile in rfiles:
      allfiles.append(rfile.filename)
  
  return allfiles
  </code></pre>
  
  <p>My screen (html) shows rows of ([Delete] and Filename). When the user clicks the [Delete] button, the following delete code snippet works (filename is /bucket/filename, complete)</p>
  
  <pre><code>filename = self.request.get('filename')
  try:
      gcs.delete(filename)
  except gcs.NotFoundError:
      pass
  </code></pre>
  
  <p>My question - given I have a list of files on-screen, I want the user to click on the filename and for that file to be downloaded to the user's computer.  In Google's Chrome Browser, this would result in the file being downloaded, with it's name displayed on the bottom left of the screen.</p>
  
  <p>One other point, the above example is for .pdf files.  I will also have to show .csv files in the list and would like them to be downloaded as well.  I only want the files to be downloaded, no display is required.</p>
  
  <p>So, I would like a snippet like ...</p>
  
  <pre><code>filename = self.request.get('filename')
  try:
      gcs.downloadtousercomputer(filename) ???
  except gcs.NotFoundError:
      pass
  </code></pre>
  
  <p>I think I have tried everything I can find both here and elsewhere.  Sorry I have been so long-winded.  Any hints for me?  </p>