2

Generated a presigned_url for a csv file on S3. If I put the url in the browser it opens without any issues.

I want the user to be able to click a link and have the file download onto their computer without touching the server if possible.

The following fails with the error:

ActionController::MissingFile at /foo/1/download
Cannot read file FILE_URL

class FooController < ApplicationController

  def download
    @foo = Foo.find_by( id: params[:id] )
    send_file( @foo.url, filename: @foo.filename )
  end

end

This redirect works without a problem and the file is displays in the browser.

class FooController < ApplicationController

  def download
    @foo = Foo.find_by( id: params[:id] )
    redirect_to @foo.url
  end

end
Curt
  • 325
  • 1
  • 3
  • 12

1 Answers1

4

To download files from s3 you need to use send_data over send_files.

see this answer for a full example

Community
  • 1
  • 1
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139