Reputation: 369
I am currently able to send a docx file for the user to download, question is how do I save the file created for download from the send_file
method to store into a local directory in a ruby app?
Below is the code that uses send_file
:
send_file rand_file, :type => 'docx', :filename => "#{@report.report_name}.docx"
Upvotes: 0
Views: 804
Reputation: 369
I've finally solve my problem by using tips from @katafrakt and @rantingsonrails by using the FileUtils method of copying just before the send_file command. Below are my code on how i did it.
temp_file_path = "./document/#{@report.report_name}.docx"
FileUtils::copy_file(rand_file,temp_file_path)
Upvotes: 1
Reputation: 568
Save the file prior to calling send_file and then reference it as such
file = File.open(temp_file_path, 'w+')
file.binmode
file.write(rand_file.read)
file.close
file = Tempfile.new('temp_file_path', 'tmp')
send_file file, ...
Upvotes: 1