I use ruby 1.9.3 and redmine 1.4.4
According to this -> Please help me send a jpg file using send_data , I do that in a controller:
@file = temp.path
File.open(@file, 'r') do |f|
send_data f.read, :filename => "myfile.pdf", :type => "application/pdf", :disposition => "attachment"
end
File.delete(@file)
But it returns ArgumentError (invalid byte sequence in UTF-8)
, why ?
The PDF file has to be encoded
file = temp.path
File.open(file, 'r') do |f|
send_data f.read.force_encoding('BINARY'), :filename => filename, :type => "application/pdf", :disposition => "attachment"
end
File.delete(file)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With