首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >回形针处理器在S3上的超时

回形针处理器在S3上的超时
EN

Stack Overflow用户
提问于 2012-09-07 09:43:34
回答 2查看 1.2K关注 0票数 1

我正在将一个数字签名插入到我的处理器中的一个pdf文件中,但是始终得到一个AWS::S3::ERRORS::Requestimeout错误。这个超时时间是什么?在文件上传之前,我有没有办法让连接保持打开?

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

这是我的代码:

模型:

代码语言:javascript
复制
...

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

...

处理器

代码语言:javascript
复制
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      
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-10 16:07:55

我已经通过使用“后保存”来解决这个问题。见我对这个问题的回答,here

票数 0
EN

Stack Overflow用户

发布于 2017-02-28 20:17:40

从今天起,您要寻找的东西不在文档中。您需要创建一个AWS::S3::Client

我指的是:https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/storage/s3.rb#L263

代码语言:javascript
复制
   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
        )
      }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12315643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档