views:

34

answers:

2

Hi All,

I have a rails application that generates open office files, and I have a service at another location that will convert these open office files to microsoft office files. I'd like to have a controller action that will send the open office file to the converter, then serve the returned microsoft office file to the user. how could I do this?

-C

+2  A: 

Check out

send_file @file.path, :x_sendfile => true

at apidock.

This allows you to serve files from the filesystem with rails authentication, but serving the actual file will go through your apache/lighttd module and won't tie up a rails process.

As far as getting the MS office document back, you will probably want the service to call a different action, which tells your rails app to download the new document.

class MyController < ApplicationController
  def get_new_document
    unless params[:file_path].nil? or params[:server_uri].nil?
      @new_document = Net::Http.get(params[:server_uri], params[:file_path])
      @new_document.save # save to filesystem
    end
  end
end
erik
A: 

x_sendfile isn't available if you happen to be using nginx, if you are you can use X-Accel-Redirect. You can find more information here:

http://kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/
jonnii