开发者

Ruby on Rails - send_file

I am using the send_file method to download a file. It works fine on my local machine. But it's not working开发者_运维百科 on the server - it returns a blank file.

code:

send_file Rails.root.join('public', 'uploads') + (uploaded_file.original_filename + ".filtered")

Please help.


Depending on what web server you are using, you may have to change the sendfile settings in your config/environments/production.rb.

For example, for nginx, you need to uncomment out this line:

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'


Try:

send_file Rails.public_path.join('uploads', "#{uploaded_file.original_filename}.filtered")

Note also that if you have files within the public directory these can be served directly, so you could redirect to the generated URL for the item (though this may not be very REST-ful).


Edit:

Because of the non-standard '.filtered' file extension, you may need to do something like:

send_file Rails.public_path.join('uploads', "#{uploaded_file.original_filename}.filtered"), :type => 'application/xml', :disposition => 'attachment'

Change the :type value to match the content type of the file being served.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜