Search code examples
ruby-on-railsrackspace-cloudrackspacesendfile

create a download link with rails to an external file with at URL


I moved my file storage to Rackspace Cloudfiles and it broke my send_file action.

old

def full_res_download
  @asset = Asset.find(params[:id])
  @file = "#{Rails.root}/public#{@asset.full_res}"
  send_file @file
end

new

def full_res_download
  @asset = Asset.find(params[:id])
  @file = "http://86e.r54.cf1.rackcdn.com/uploads/fake/filepath.mov"
  send_file @file
end

When the files were in the public file. the code worked great. When you click in the link the file would download and the webpage would not change. Now it gives this error.

Cannot read file http://86e.r54.cf1.rackcdn.com/uploads/fake/filepath.mov

What am i missing?

Thank you so much for your time.


Solution

  • what worked

    def full_res_download
      @asset = Asset.find(params[:id])
      @file = open("http://86e.r54.cf1.rackcdn.com/uploads/fake/filepath.mov")
      send_file( @file, :filename => File.basename(@asset.file.path.to_s))
    end
    

    real code

    controler.rb

    def web_video_download
      @asset = Asset.find(params[:id])
      @file = open(CDNURL + @asset.video_file.path.to_s)
      send_file( @file, :filename => File.basename(@asset.video_file.path.to_s))
    end
    

    development.rb

    CDNURL = "http://86e.r54.cf1.rackcdn.com/"