Rails将PDF作为可下载文件发送

时间:2019-07-02 08:59:29

标签: ruby-on-rails

我想将Rails的pdf文件发送到浏览器。它只是以.pdf结尾的api的正常调用。喜欢

/detail/ac67857a-ad71-4a97-9718-c71c47e2e4bc.pdf

这是我的控制器代码

format.pdf {
        download_result_from_aws = export_pdf_service.get_file_from_aws(upload_result[:key])
        File.open(download_result_from_aws, 'r') do |f|
          send_data f.read.force_encoding('BINARY'), :filename => export_pdf_service.filename, :type => "application/pdf", :disposition => "attachment"
        end
      }

,但尚未下载。这样的反应

%PDF-1.4
1 0 obj
<<
/Title (þÿ)
/Creator (þÿwkhtmltopdf 0.12.4)
/Producer (þÿQt 4.8.7)
/CreationDate (D:20190702155100+07'00')
>>
endobj
3 0 obj
<<
/Type /ExtGState
/SA true
/SM 0.02
/ca 1.0
/CA 1.0
/AIS false
/SMask /None>>
endobj
4 0 obj
[/Pattern /DeviceRGB]
endobj
7 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 600
/Height 714
/BitsPerComponent 8
/ColorSpace /DeviceGray
/Length 8 0 R
/Filter /FlateDecode
>>
stream
xíwÅÇ7×£7éÒ-tTP¢"ØfAE¨ØP~º
©ôÞ98:å¸^r)óý

该如何解决? 谢谢你

0 个答案:

没有答案