Ruby-Rails serve ftp file direct to client

后端 未结 2 1752
死守一世寂寞
死守一世寂寞 2020-12-18 16:51

I am new to ruby and to rails, so excuse my question... . What i want to know is, how to take a file from a ftp server with ruby without saving the file on my rails applicat

2条回答
  •  眼角桃花
    2020-12-18 17:32

    thank you very much for your support! Your post get me going on. After some cups of coffee i found a working solution. Actually i am doing the following, which works for me:

    def download_file
      filename = params[:file]
      raw = StringIO.new('')
      @ftp.retrbinary('RETR ' + filename, 4096) { |data|
        raw << data
      }
      @ftp.close
      raw.rewind
      send_data raw.read, :filename => filename
    end
    

    I will test this in production(real life situation). If this is not working well enough, i have to use a NFS mount.

    fin

提交回复
热议问题