1

I'm using a form to post data to a rails controller. The data sent is a excel file's binary data and the controller should echo it back for the browser to trigger a download. (I must do it this way).

The issue is that I get a warning in Chrome:

Resource interpreted as Document but transferred with MIME type      application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: "http://192.168.2.39:3000/resources/export"

What I see as strange is that Rails shows "Rendered text template" at the end of the request.

Here is the controller action:

def export
    begin
        cookies.delete(:download_token)
        cookies[:download_token] = params[:download_token] 
        send_data  Base64.decode64(params[:data]), :filename => 'Tasks.xls', :type =>   'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8; header=present', :disposition => 'attachment'
    rescue Exception => e
        render nothing: true
    end
end

And this is the end of the output of the export action:

"application/x-www-form-urlencoded"
Rendered text template (0.0ms)
Sent data Tasks.xls (1.2ms)
Completed 200 OK in 5006ms (Views: 0.9ms | ActiveRecord: 0.0ms)

I'm using Rails 4.
The request comes from form which targets an iframe in a EXT js 4 app.
The whole app has some html views and some views which use ext js.
I am using the turbolinks gem for the html views.

The file is actually sent and the browser triggers the download. Its just the warning I want to get rid of.

Update

I disabled turbolinks and the warning is still there.

spiria
  • 106
  • 1
  • 11
  • If my MIME Type resolution does not work take a look at this [SO Question](http://stackoverflow.com/questions/14818015/rails-wont-send-data-as-file) – engineersmnky Jul 30 '14 at 20:29

1 Answers1

2

I found a fix for the warning on Chrome. Apparently the error on Safari is an error that comes up on every download, not particular to my application.

In config/initializers/mime_types.rb:

Mime::Type.register "vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xls

In my controller:

send_data  Base64.decode64(params[:data]), :filename => 'Tasks.xls', :type => :xls, :disposition => 'attachment', :layout => false

This made the warning on Chrome dissappear. Hope it helps.

spiria
  • 106
  • 1
  • 11