我使用ruby 1.9.3和redmine 1.4.4
根据这个 - > Please help me send a jpg file using send_data,我在控制器中执行此操作:
@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)
但它返回ArgumentError (invalid byte sequence in UTF-8)
,为什么?
答案 0 :(得分:8)
PDF文件必须编码
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)