I have a controller action that is meant to send a file to the user for download from my bucket in S3.
Here’s the controller code:
send_file @project.file.url, :type => @project.file_content_type
Here’s the error:
Cannot read file http://s3.amazonaws.com/bucket/projects/1/project.xlsx?2011
When I go to the URL directly, I get a download of the file! What’s going on?
Is it ok if you just redirect the user to the file on S3?
The issue is that
send_fileexpects a path to a local file, which is then used by the webserver to serve up data from the local file it can access on disk. The file on S3 is only accessible by HTTP, so your webserver can’t serve it. To usesend_fileyou’d have to download it and then serve it I think.