【问题标题】:google app engine python download file谷歌应用引擎python下载文件
【发布时间】:2010-05-04 18:21:05
【问题描述】:

我正在尝试找出一种方法来创建一个包含来自用户定义字段的数据的制表符分隔文件,并允许用户在谷歌应用引擎上下载该文件。

应用运行的沙盒环境不允许应用写入磁盘。还有其他方法可以创建可下载文件吗?

【问题讨论】:

    标签: python google-app-engine download


    【解决方案1】:

    当然有!例如,您可以将数据输出为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']))
    

    【讨论】:

      【解决方案2】:

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

      self.response.headers['Content-Disposition'] = "attachment; filename=fname.csv"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-11
        • 2014-07-20
        • 2011-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-01
        相关资源
        最近更新 更多