【发布时间】:2017-01-23 21:26:09
【问题描述】:
在我的 Rails 应用程序中使用 Paperclip 进行文件上传,我需要在上传到 Amazon S3 服务器之前将图像转换为单独的 PDF。我知道我可以使用 Prawn 将图像转换为 PDF,并且可以使用this stack overflow question的答案截取文件
在模型中:
has_attached_file :file
before_file_post_process :convert_images
...
def convert_images
if file_content_type == 'image/png' || file_content_type == 'image/jpeg'
original_file = file.queued_for_write[:original]
filename = original_file.path.to_s
pdf = Prawn::Document.new
pdf.image open(filename), :scale => 1.0, position: :center
file = pdf.render
end
end
但是,我无法实际转换存储在 S3 上的图像。有什么我想念的想法吗?
编辑:添加 save! 调用会导致验证失败,而以前不会这样做。
【问题讨论】:
标签: ruby-on-rails pdf amazon-s3 paperclip prawn