1

我希望在下载文件时向客户端显示文件的大小。
但是 HTTP Header Content-Length 不起作用。
我的环境是跟随。

  • 阿帕奇 2.2
  • mod_deflate
  • Rails3.2

下载文件位于 rails 项目的公共文件夹中。

当我下载它时,响应标题是这个。

Accept-Ranges bytes
Access-Control-Allow-Head... origin, x-requested-with, content-type
Access-Control-Allow-Meth... PUT, GET, POST, DELETE, OPTIONS
Access-Control-Allow-原始... http:// * .com
Connection Keep-Alive
Content-Encoding gzip
Content-Type application/octet-stream
日期 Fri, 14 Dec 2012 05:15:09 GMT
Etag "c1bcc-1c828800-4d0a3ac0f7389"
Keep-Alive timeout=5, max=100
Last-Modified Wed, 12 Dec 2012 08:34:51 GMT
Server Apache
Transfer-Encoding chunked
Vary Accept-Encoding

有没有办法显示内容长度?

4

1 回答 1

1

Although this is an old thread, it is a problem related to gzip compression. For others reading this question, here is my solution, based on this thread:

How to disable Apache gzip compression for some media files in .htaccess file?

You can add the following rule to your .htaccess

SetEnvIfNoCase Request_URI \.(?:gif|png|pdf|xxx)$ no-gzip dont-vary

if you want to disable compression for certain file types or

SetEnvIfNoCase Request_URI (url_to_not_compress) no-gzip dont-vary

if you have a script that forces a file to download.

于 2014-11-26T15:36:56.700 回答