第一次尝试使用 Internet Explorer 下载 CSV 失败,但在后续尝试中可以正常下载
这已经让我失望太久了。
下面发布的是我们的 Rails 3 控制器。
首次尝试使用 Internet Explorer 访问时,下载提示失败,并显示“无法下载”消息。
当尝试立即访问相同的 URL 时,下载提示成功运行。
在任何情况下,Cache-Control 标头都没有正确发送。我们为机架响应提供特定值,但缓存控制始终以“缓存控制:无缓存”的形式返回。不过,提供的其他标头值已正确发送。这可能是一个单独的问题,但无论如何都让我失望。
下面的示例模拟了我们的实际系统如何处理客户端数据。 CSV 启动并传输到客户端。下载是渐进式的,以避免 CSV 生成完成时的长时间等待。这些文件可能超过 20-30mb,因此在下载开始之前等待几分钟是不可取的。
这似乎适用于所有其他浏览器(firefox、safari 等)。
class StreamingController < ApplicationController
def index
respond_to do |wants|
wants.csv {
filename = "testing_filename#{DateTime.now}.csv"
headers.merge!({
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Content-Type' => 'text/csv',
'Content-Disposition' => "attachment; filename=\"#{filename}\"",
'Content-Transfer-Encoding' => 'binary'
})
responder = Rack::Response.new([], 200, headers) do |response|
response.finish do |r|
100000.times do |t|
r.write(t)
end
end
end
self.response_body = responder
}
end
end
end
this has been throwing me off for too long..
Posted below is our Rails 3 controller.
When attempting to access with Internet Explorer the first time, the download prompt fails with a "Unable to download" message.
When attempting to access the same URL immediately following, the download prompt works successfully.
In any instance, the Cache-Control header is not being sent properly either. We are providing a specific value to the Rack Response, yet the Cache-Control is always being returned as "Cache-Control: no-cache". The other header values provided are being sent correctly though. This may be a separate question, but throwing me off regardless.
The sample below is a mock of how our actual system works with client data. A CSV is started and streamed to the client. The download is progressive, to avoid a long wait time while the CSV generation is complete. These files can be upwards of 20-30mb, so waiting a few minutes before a download starts is not desirable.
This appears to be working in all other browsers (firefox, safari, etc).
class StreamingController < ApplicationController
def index
respond_to do |wants|
wants.csv {
filename = "testing_filename#{DateTime.now}.csv"
headers.merge!({
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Content-Type' => 'text/csv',
'Content-Disposition' => "attachment; filename=\"#{filename}\"",
'Content-Transfer-Encoding' => 'binary'
})
responder = Rack::Response.new([], 200, headers) do |response|
response.finish do |r|
100000.times do |t|
r.write(t)
end
end
end
self.response_body = responder
}
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题可能与 http://support.microsoft.com/kb/316431 有关 - 尝试省略标题“Cache-Control”中的“must-validate”并查看它是否有效。如果没有尝试完全省略标题。对于发送的“无缓存”部分,请求是否可能通过添加此部分的代理?
斯文
This issue could be related to http://support.microsoft.com/kb/316431 - Try to omit "must-validate" in the header "Cache-Control" and see if it works. If not try to omit the header completely. For the "no-cache" part being sent along, is the request possibly going through a proxy that is adding this?
Sven