Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google app engine python download file

I am trying to figure out a way where I can create a tab-delimited file containing data from user-defined fields and allow the user to download that file on google app engine.

The sandbox environment that the app runs in does not allow the application to write to disk. Is there another way where I can create a downloadable file?

like image 555
MattM Avatar asked May 04 '10 18:05

MattM


People also ask

How do I download and install Google App Engine?

You can download the Google App Engine SDK by going to: http://code.google.com/appengine/downloads.html and download the appropriate install package. Download the Windows installer – the simplest thing is to download it to your Desktop or another folder that you remember.


2 Answers

Sure there is! You can output your data as csv, for instance. All you need to do is to change the Content-Type header.

It's something like this:

class Test(webapp.RequestHandler):
    def get(self, upload_type):
        self.response.headers['Content-Type'] = 'text/csv'
        self.response.out.write(','.join(['a', 'cool', 'test']))
like image 101
jbochi Avatar answered Oct 11 '22 21:10

jbochi


In addition to jbochi's answer, you can also add a Content-Disposition header to save using a particular filename.

self.response.headers['Content-Disposition'] = "attachment; filename=fname.csv"
like image 22
cnu Avatar answered Oct 11 '22 20:10

cnu