ruby-on-rails - Rails 将 PDF 作为可下载文件发送
问题描述
我想将 pdf 文件从 rails 发送到浏览器。它只是正常调用最后带有 .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)óý
如何解决?非常感谢你
解决方案
推荐阅读
- powershell - 为什么字符串作为 ArrayLists 传递
- cassandra - ScyllaDB/Cassandra 如何处理部分更新?
- ios - 自定义 SLComposeSheetConfigurationItem
- python - 如何遍历字典以在 django 的前端显示并实现用户输入
- ios - UITableView Swift 将静态部分与动态部分结合起来
- javascript - 如何每 x 秒更改一次状态
- python-3.x - 在 python 3 中使用 Scapy 读取 SSL 证书
- reactjs - 如何使用 Jquery 在 reactjs 中根据日期更新 dom?
- excel - 将宏分配给按钮以将数据从表 1/表 2 复制到数据表而不是删除的简单方法
- amazon-ec2 - AWS Clear Linux AMI 未运行用户数据