I am using following code for sending the file in Rails.
if File.exist?(file_path) send_file(file_path, type: \'text/excel\') File.delete(file_path) end
This works for me! With send_data you can delete file before send.
send_data
file = File.open(Rails.root.join('public', 'uploads', filename), "rb") contents = file.read file.close File.delete(filepath) if File.exist?(filepath) send_data(contents, :filename => filename)