exposing files from a service through a rails application

佐手、 提交于 2019-12-23 03:01:27

问题


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


回答1:


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



回答2:


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/


来源:https://stackoverflow.com/questions/1213957/exposing-files-from-a-service-through-a-rails-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!