11

I'm sending a ms-word file using rails. i.e when I click on a link, a doc file from tmp folder (in project) is sent.

The code I'm using is

@filename ="#{RAILS_ROOT}/tmp/test/test.doc"
send_file(@filename ,
            :filename      =>  "test",
            :type          =>  'application/msword',
            :disposition  =>  'attachment',
            :streaming    =>  'true',
        :buffer_size  =>  '4096')

It's working, but it's sending an empty file. Content is missing in the file. Any suggestions?

1
  • 2
    +1. Make sure you don't send an empty file. Commented Apr 18, 2010 at 16:48

4 Answers 4

15

There is no send_file :streaming option, it is :stream. You're passing bad parameters types. :buffer_size should be number, not a string. :stream should be boolean, not string.

:stream => true,
:buffer_size => 4096,

You need only filename parameter (if you want to send file with another name than the original). Other options you are using are default (except :type).

Can you try this ?

@filename ="#{RAILS_ROOT}/tmp/test/test.doc"
send_file(@filename, :filename => "test.doc")
Sign up to request clarification or add additional context in comments.

Comments

3

comment out the following line in config/environments/production.rb

config.action_dispatch.x_sendfile_header = "X-Sendfile"

1 Comment

For nginx it's X-Accel-Redirect.
1
In your view =>
<%= link_to "click here to download", signed_feeds_pdf_path(:feed_image_path => feed_image.feedimage.path), target: '_self' %>
In your controller =>
  def pdf
    file_name = params[:feed_image_path].split('/').last
    @filename ="#{Rails.root}/public/uploads/feed_image/feedimage/#{file_name}"
    send_file(@filename ,
      :type => 'application/pdf/docx/html/htm/doc',
      :disposition => 'attachment')           
  end

Comments

0

Try sending with :disposition => 'inline'

send_file path, :type => 'application/msword', :disposition => 'inline'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.