2

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

4

3 に答える 3

1

ダウンロードしたいファイルがcsvファイルなのでトライ

resp.setContentType( "text/plain" );
resp.setHeader( "Content-Disposition:", "attachment; filename=" + fileName);
于 2013-11-07T21:27:30.970 に答える
0

「text/plain」の代わりに「text/csv」または「application/csv」を試してみてください。どちらも機能しました。

于 2013-12-17T18:53:44.543 に答える