开发者

CSV download fails with Internet Explorer on first attempt, works on subsequent attempts

this has been throwing me off for too long..

Posted below is our Rails 3 controller.

  1. When attempting to access with Internet Explorer the first time, the download prompt fails with a "Unable to download" message.

  2. When attempting to access the same URL immediately following, the download prompt works successfully.

  3. In any instance, the Cache-Control header is not being sent prop开发者_StackOverflow社区erly 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜