문제

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top