2012-09-07 25 views
1

我在我的處理器中插入了一個數字簽名到pdf文件,但不斷收到AWS::S3::ERRORS::Requestimeout錯誤。這是什麼超時?有什麼辦法可以保持連接打開,直到文件上傳?S3上的回形針處理器超時

到服務器的套接字連接在超時期限內未被讀取或寫入 。空閒連接將被關閉。

這裏是我的代碼:

型號:

... 

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 protected]", 
      :reason => "Proof of Concept" 
     ) 

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

回答

0

我身邊有這個工作,通過使用後保存。請參閱我的與此主題相關的答案here

0

您要查找的內容不在今天的文檔中。你需要創建一個AWS :: S3 ::客戶

我引用: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 
     ) 
     } 
    } 
相關問題