大虾生成的证书的url如何获取?
How do i get the url of certificate generated using prawn?
我知道如何在 webapp 中呈现它,但我应该通过 api 调用生成 pdf,所以我需要发送生成的 pdf 的 url 而不是 pdf 本身(这就是移动开发人员所要求的),有什么办法可以做到吗?
喜欢:
respond_to do |format|
format.pdf do
pdf = CustomCertificatePdf.new(current_user, tutorials)
url = pdf.link
# send_data pdf.render, filename: "custom_certificate_#{current_user.first_name.downcase}_#{current_user.last_name.downcase}.pdf",
# type: "application/pdf",
# disposition: "inline"
render :json => {url: url}
end
end
即使是您的轻微提示也将不胜感激,谢谢 :)
将 pdf 保存到 public
文件夹或上传到另一台服务器(S3、google 驱动器、保管箱...)
然后在 api controller
中使用 link
如果您将 pdf 文件保存在 public
文件夹中,link 应该是您的主机名 + 与 public
文件夹
的相对路径
例如:
file_path = "/webapp/public/pdf/custom_certificate.pdf"
link应该是
http://yourhostname.com/pdf/custom_certificate.pdf
如果你需要保护你的文件,你应该写另一个控制器来为它提供身份验证
这就是我最后做的事情
pdf = CustomCertificatePdf.new(current_user, tutorials)
@filename = File.join("custom_certificate_#{current_user.first_name.downcase}_#{current_user.last_name.downcase}.pdf")
pdf.render_file @filename
current_user.cust_cert = File.open("custom_certificate_#{current_user.first_name.downcase}_#{current_user.last_name.downcase}.pdf")
current_user.save!
render :json => {url: "#{current_user.cust_cert}"}
在用户模型中
has_mongoid_attached_file :cust_cert,
:default_url => "",
:path => ':attachment/:id/:cust_cert',
:storage => :s3,
:url => ':s3_domain_url',
:s3_credentials => File.join(Rails.root, 'config', 's3.yml')
validates_attachment_content_type :cust_cert, :content_type => [ 'application/pdf' ], :if => :cust_cert_attached?
def cust_cert_attached?
self.cust_cert.file?
end
我知道如何在 webapp 中呈现它,但我应该通过 api 调用生成 pdf,所以我需要发送生成的 pdf 的 url 而不是 pdf 本身(这就是移动开发人员所要求的),有什么办法可以做到吗?
喜欢:
respond_to do |format|
format.pdf do
pdf = CustomCertificatePdf.new(current_user, tutorials)
url = pdf.link
# send_data pdf.render, filename: "custom_certificate_#{current_user.first_name.downcase}_#{current_user.last_name.downcase}.pdf",
# type: "application/pdf",
# disposition: "inline"
render :json => {url: url}
end
end
即使是您的轻微提示也将不胜感激,谢谢 :)
将 pdf 保存到 public
文件夹或上传到另一台服务器(S3、google 驱动器、保管箱...)
然后在 api controller
如果您将 pdf 文件保存在 public
文件夹中,link 应该是您的主机名 + 与 public
文件夹
例如:
file_path = "/webapp/public/pdf/custom_certificate.pdf"
link应该是
http://yourhostname.com/pdf/custom_certificate.pdf
如果你需要保护你的文件,你应该写另一个控制器来为它提供身份验证
这就是我最后做的事情
pdf = CustomCertificatePdf.new(current_user, tutorials)
@filename = File.join("custom_certificate_#{current_user.first_name.downcase}_#{current_user.last_name.downcase}.pdf")
pdf.render_file @filename
current_user.cust_cert = File.open("custom_certificate_#{current_user.first_name.downcase}_#{current_user.last_name.downcase}.pdf")
current_user.save!
render :json => {url: "#{current_user.cust_cert}"}
在用户模型中
has_mongoid_attached_file :cust_cert,
:default_url => "",
:path => ':attachment/:id/:cust_cert',
:storage => :s3,
:url => ':s3_domain_url',
:s3_credentials => File.join(Rails.root, 'config', 's3.yml')
validates_attachment_content_type :cust_cert, :content_type => [ 'application/pdf' ], :if => :cust_cert_attached?
def cust_cert_attached?
self.cust_cert.file?
end