谷歌应用程序引擎python下载文件

Mat*_*ttM 13 python google-app-engine download

我试图找出一种方法,我可以创建一个包含用户定义字段数据的制表符分隔文件,并允许用户在谷歌应用程序引擎上下载该文件.

应用程序运行的沙箱环境不允许应用程序写入磁盘.还有另一种方法可以创建可下载的文件吗?

jbo*_*chi 27

当然有!例如,您可以输出数据csv.您需要做的就是更改Content-Type标题.

它是这样的:

class Test(webapp.RequestHandler):
    def get(self, upload_type):
        self.response.headers['Content-Type'] = 'text/csv'
        self.response.out.write(','.join(['a', 'cool', 'test']))
Run Code Online (Sandbox Code Playgroud)


cnu*_*cnu 20

除了jbochi的答案,您还可以添加Content-Disposition标头以使用特定文件名进行保存.

self.response.headers['Content-Disposition'] = "attachment; filename=fname.csv"
Run Code Online (Sandbox Code Playgroud)