send_file just sends an empty file

Viewed 6324

Im looking for a way to download a xml file. I use:

file_path = 'folder/' + xml_name + '.xml'
send_file file_path, :type => "text/xml"

but this always downloads me an empty file. The file itself has 16 KB of data in it...

why is that?

Maechi

5 Answers

In my case same thing happened. I was sending file and deleting it.
as here

File.open(file_path, 'r') do |f|      
  send_data f.read, filename: 'my_file.docx' , type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', disposition: 'attachment'
end
File.delete(file)

but

filename: 'my_file.docx'

save my day

Related