向API发出请求
def update
# ...
conn = Faraday.new(url: 'http://localhost:1111')
conn.basic_auth('login', 'password')
body = conn.get('/path/to/api', { guid: "123-456", pdf: 'true' } )
# ...
end
在另一面:
send_file(pdf_path, { filename: "#{name}.pdf", disposition: 'inline', type: 'application/pdf' })
send_file(docx_path, { filename: "#{name}.docx", disposition: 'inline', type: 'application/application/document' })
返回:
"%PDF-1.7\r%\xCD\xCA\xD2\xA9\r1 0 obj\n<<\n/Metadata 4 0 R\n/PageLayout /OneColumn\n/PageMode /UseNone\n/Pages 2 0 R\n/Type /Catalog\n>>\nendobj\n2 0 obj\n<<\n/Count 1\n/Kids [ 6 0 R ]\n/Type /Pages\n>>\nendobj\n3 0 obj\n<<\n/CreationDate (D:20190214133454+00'00')\n/ModDate (D:20190214133454+00'00')\n/Producer (\xFE\xFF\\000A\\000s\\000c\\000e\\000n\\000s\\000i\\000o\\000\\040\\000S\\000y\\000s\\000t\\000e\\000m\\000\\040\\000S\\000I\\000A\\000\\040\\000C\\000o\\000p\\000y\\000r\\000i\\000g\\000h\\000t\\000\\040\\000\\050\\000c\\000\\051\\000\\040\\0002\\0000\\0001\\0008)\n>>\nendobj\n4 0 obj\n<<\n/Length 5 0 R\n/Subtype /XML\n/Type /Metadata\n>>\nstream\r\n<?xpacket begin=\"\xEF\xBB\xBF\ ................"
如何将其保存到文件中?
使用 carrierwave 。
request.document = body.body
document.save
但这不起作用