我有一个带回形针附件(图像或pdf文件)的模型。我正在使用Sidekiq在后台进程中处理此模型。
这个转换在我的开发环境的sidekiq和我的中间服务器的sidekiq上工作得很好,但它不能在生产服务器的sidekiq上工作。在我的生产服务器上,如果我从Rails控制台运行转换方法,它就可以工作。当它不工作时,dst文件为空,返回的字符串为''
模型看起来像这样
class Receipt < ActiveRecord::Base
has_attached_file :image, styles: { original: {} }, path: ':rails_root/attachments/:class/:attachment/:id_partition/:style/:filename'
validates_attachment_content_type :image, :content_type => IMAGE_MIME_TYPES
def convert_pdf_to_pdf_string
if %w(application/pdf application/octet-stream).include?(image.content_type)
begin
dst = Tempfile.new([File.basename(image.path, File.extname(image.path)), '.pdf'], :encoding => 'ascii-8bit')
dst.flush
`convert -density 200 #{image.path.shellescape} #{dst.path.shellescape}`
dst
str = File.open(dst.path, 'rb') {|f| f.read}.to_s
ensure
dst.close
dst.unlink
end
end
end
end我不知道如何调试这个问题。
没有引发任何异常。我还试图记录backticks调用的返回值,但没有返回任何内容。
请提出我应该检查的任何想法。
发布于 2016-06-15 16:23:19
我开始研究如何让convert生成一些日志记录。在我将反引号调用更改为
`convert -density 200 #{image.path.shellescape} #{dst.path.shellescape} 2>log/magick_error.log 1>log/magick.log`代码开始工作了。导入到它生成的magick_error.log中
**** Warning: File has some garbage before %PDF- .所以我猜STDERR的输出是在我的生产环境中搞砸了一些事情。阶段性和开发环境可以容忍这一点。
https://stackoverflow.com/questions/37828488
复制相似问题