通过rails应用程序从服务中暴露文件 [英] exposing files from a service through a rails application

查看:99
本文介绍了通过rails应用程序从服务中暴露文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个rails应用程序可以生成打开的office文件,而我在另一个位置提供服务,将这些打开的office文件转换成microsoft office文件。我想要一个控制器操作,将打开的办公室文件发送到转换器,然后将返回的微软Office文件提供给用户。我该怎么做?



-C

解决方案

  send_file @ file.path,:x_sendfile => true 

at apidock



这允许您使用rails身份验证从文件系统提供文件,但服务实际文件将会通过您的apache / lighttd模块,并不会绑定一个rails进程。



只要获得MS Office文档,您可能希望该服务调用不同的操作,它告诉你的rails应用来下载新的文档。

  class MyController< ApplicationController 
def get_new_document
除非params [:file_path] .nil?或params [:server_uri] .nil?
@new_document = Net :: Http.get(params [:server_uri],params [:file_path])
@ new_document.save#保存到文件系统
end
end
end


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

解决方案

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

这篇关于通过rails应用程序从服务中暴露文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆