您的位置:首页 > 移动开发 > WebAPP

google app engine(webapp2)文件下载

2014-02-25 16:56 495 查看
enroll_file = "enroll.mobileconfig"
filecontent = open('./conf/' + enroll_file, "rb").read()
self.response.headers.add_header('Content-Type','application/octet-stream')
self.response.headers.add_header('Content-Disposition', 'attachment; filename="' + enroll_file + '"')
self.response.headers.add_header('Content-Length',str(len(filecontent)))
self.response.out.write( filecontent )


在IE中测试上述代码,发现有时候下载框不能正常显示文件名,从而导致保存不了,但在firefox和safari中是正常的。

以上代码改成以下形式也可:

self.response.headers['Content-Type'] = 'application/octet-stream'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: