我使用 ruby 1.9.3 和 redmine 1.4.4
据此-> Please help me send a jpg file using send_data ,我在 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)
但它返回ArgumentError(UTF-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)
关于ruby-on-rails - 使用 rails send_data 发送 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23083983/