如何使用Google AppEngine设置文件下载的文件名?我尝试设置Content-Disposition
,但AppEngine在生产中删除了标题(在开发中工作)。
resp.setContentType( "application/octet-stream" );
resp.setHeader( "Content-Disposition:", "attachment; filename=" + "\"" + fileName + "\"" );
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="logs-2013-11-06-15-23-21.csv"
HTTP/1.1 200 OK
Content-Type: application/octet-stream
X-AppEngine-Estimated-CPM-US-Dollars: $0.001434
X-AppEngine-Resource-Usage: ms=220 cpu_ms=224
Date: Wed, 06 Nov 2013 20:25:00 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, must-revalidate
Server: Google Frontend
Content-Length: 12713
Alternate-Protocol: 80:quic
https://developers.google.com/appengine/docs/java/#Java_Responses https://code.google.com/p/googleappengine/issues/detail?id=10247
答案 0 :(得分:3)
晚会......
只是它有帮助,setHeader的第一个参数应该是“Content-Disposition”(尾随:应该不存在)。
Chrome浏览器的保存对话框然后识别提供的文件名值。 (在我的应用程序中,内容类型被设置为“application / octet-stream”)。这对我有用:
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename='" + filename + "'");
答案 1 :(得分:1)
由于您要下载的文件是csv文件,请尝试
resp.setContentType( "text/plain" );
resp.setHeader( "Content-Disposition:", "attachment; filename=" + fileName);
答案 2 :(得分:0)
尝试“text / csv”或“application / csv”而不是“text / plain”,两者都有效。