1

我正在将数字签名插入到处理器内的 pdf 文件中,但不断出现AWS::S3::ERRORS::Requestimeout错误。这是什么超时?有什么办法可以在文件上传之前保持连接打开?

在超时期限内未读取或写入您与服务器的套接字连接。空闲连接将被关闭。

这是我的代码:

模型:

...

has_attached_file :receipt_file,
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml",
                    :path => "/:style/:id/:filename",
                    :s3_protocol => "https",
                    :styles => {dummy:""},
                    processors: [:SignPdf]
 #process_in_background :receipt_file

...

处理器

module Paperclip


    class SignPdf < Processor
      attr_accessor :receipt_id,:style
     S3_CONFIG = YAML.load_file("#{::Rails.root}/config/s3.yml")[Rails.env]
     ORIGAMIDIR = "/ruby/1.9.1/gems/origami-1.2.4/lib"


      def initialize(file, options = {}, attachment = nil)
        @file           = file
        @current_format = File.extname(@file.path)
        @basename       = File.basename(@file.path, @current_format)
        @attachment = attachment
      end

        def make

         signPdf(@file) 
         @file
      end

    end
end

begin
  require 'origami'
rescue LoadError
  $: << ORIGAMIDIR
  require 'origami'
end
include Origami
def signPdf(file)

        certFile = "#{::Rails.root}/lib/assets/Cert.pem"
        rsakeyFile = "#{::Rails.root}/lib/assets/pk.pem"
        passphrase = "o2Receipts"

        key4pem=File.read rsakeyFile
        key = OpenSSL::PKey::RSA.new key4pem, passphrase
        cert = OpenSSL::X509::Certificate.new(File.read certFile)

        pdf = PDF.read(file)
        page = pdf.get_page(1)

        # Add signature annotation (so it becomes visibles in pdf document)

        sigannot = Annotation::Widget::Signature.new
        sigannot.Rect = Rectangle[:llx => 89.0, :lly => 386.0, :urx => 190.0, :ury => 353.0]

        page.add_annot(sigannot)

        # Sign the PDF with the specified keys
        pdf.sign(cert, key, 
          :method => 'adbe.pkcs7.sha1',
          :annotation => sigannot, 
          :location => "Portugal", 
          :contact => "email@email.pt", 
          :reason => "Proof of Concept"
        )

        # Save the resulting file
        pdf.save(file.path)
        file
end      
4

2 回答 2

0

我已经通过使用后保存解决了这个问题。在此处查看我与此主题相关的答案

于 2012-09-10T16:07:55.387 回答
0

截至今天,您要查找的内容不在文档中。您需要创建一个 AWS::S3::Client

我参考:https ://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/storage/s3.rb#L263

   config.paperclip_defaults = {
      storage: :s3,
      s3_credentials: "#{Rails.root}/config/s3.yml",
      s3_region: ENV['AWS_REGION'],
      s3_protocol: :https,
      s3_options: {
        client: Aws::S3::Client.new(
          access_key_id: ENV['S3_KEY'],
          secret_access_key: ENV['S3_SECRET'],
          http_open_timeout: 10,
          http_read_timeout: 5,
          http_idle_timeout: 20
        )
      }
    }
于 2017-02-28T20:17:40.960 回答