I'm at a loss for this one. I've looked all over and there seem to be a lot of solutions, but they aren't working for me. I've got a CGI::Application app generating a MS Excel spreadsheet with Spreadsheet::WriteExcel. This worked fine for quite some time until our live server had a hardware failure a couple weeks ago. We used the outage as an excuse to upgrade to Windows Server 2008 (from 2003) and Apache 2.2.17 (from 2.2.11). Now, I'm getting sporadic (but too frequent to ignore) complaints from customers receiving this error when trying to download spreadsheets:
Internet Explorer cannot download [url] from [site].
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.
I have tried IE 7-8 on XP, Vista, and 7 and have been unable to reproduce this error locally. The users that have the problem have it every time, not randomly. All complaints have come from IE users, mostly on IE8.
After reading a couple posts about the error message, I added the -expires
header to no avail. (With no way to test this directly, I've had to implement a fix and wait a day or so to see if people stop complaining ._.
)
sub export_spreadsheet {
my $self = shift;
binmode STDOUT;
my $str;
open my $fh, '>', \$str;
my $workbook = Spreadsheet::WriteExcel->new($fh);
# words words words
$workbook->close;
close $fh;
$self->header_add(-type => 'application/vnd.ms-excel',
-expires => '+1d',
-attachment => 'export.xls');
return $str;
}
The headers for the request look normal. These were collected on my local machine, mind you.
HTTP/1.1 200 OK
Date: Tue, 31 May 2011 22:23:17 GMT
Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o mod_perl/2.0.4-dev Perl/v5.10.1
Expires: Wed, 01 Jun 2011 22:23:18 GMT
Content-Disposition: attachment; filename="export.xls"
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=100
Content-Type: application/vnd.ms-excel
Content-Length: 18944
Accept-Ranges: none
Proxy-Connection: Keep-Alive
The current workaround we give to customers (unable or unwilling to switch to an alternate browser) with the issue is to switch to SSL by putting typing the https
themselves. The SSL download works fine for the ones who have tried it and gotten back to us. Speculation: Could it be a downstream proxy messing with our headers? Could that be why it works in SSL and errors in plain HTTP? (The server upgrade would be an unfortunate coincidence in this case.)
According to http://support.microsoft.com/kb/316431 IE can't deal with some situations where a file isn't cached but it's then opened by some external process. It's not the exact same case, but as EricLaw mentioned in a comment, it might have something to do with the Vary
heading and the fact that the download doesn't have a file name.
I'd remove that header and give it a filename and IE should be able to save the file to disk so that it can be opened by Excel.