Ruby on Rails - send_file

I use the send_file method to upload a file. It works fine on my local machine. But it does not work on the server - it returns an empty file.

code:

 send_file Rails.root.join('public', 'uploads') + (uploaded_file.original_filename + ".filtered") 

Please, help.

+4
source share
2 answers

Depending on which web server you are using, you may need to change the sendfile settings in config/environments/production.rb .

For example, for nginx you need to uncomment this line:

 config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' 
+4
source

Try:

 send_file Rails.public_path.join('uploads', "#{uploaded_file.original_filename}.filtered") 

Please note that if you have files in the public directory, they can be sent directly, so you can redirect to the generated URL for the element (although this may not be very REST-ful).


Edit:

Due to the non-standard .filtered file extension, you may need to do something like:

 send_file Rails.public_path.join('uploads', "#{uploaded_file.original_filename}.filtered"), :type => 'application/xml', :disposition => 'attachment' 

Change the value of :type to match the type of contents of the file being served.

+1
source

All Articles