0
在我的Rails应用程序中使用Paperclip进行文件上载,并且在上传到Amazon S3服务器之前需要将图像转换为单独的PDF。我知道我可以使用虾的图像转换为PDF,我可以使用应答文件拦截this stack overflow question在使用回形针上传图片之前将图像转换为PDF
在模型:
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!
调用会导致验证失败,之前没有这样做。