在S3上回形针处理器超时 [英] Paperclip processor timeout on S3
问题描述
我插入一个数字签名到我的处理器里面的PDF文件,但不断收到 AWS :: S3 ::错误:: Requestimeout
错误。这是什么超时?有什么办法,我可以保持连接打开,直到该文件被上传?
您socket连接到服务器无法读取或写入 在超时期限内。空闲连接将被关闭。
下面是我的code:
模式:
...
has_attached_file:receipt_file,
:存储=> :S3,
:s3_credentials => #{Rails.root} /config/s3.yml
:PATH => /:款式/:ID /:文件名,
:s3_protocol => https开头,
:风格=> {假:},
处理器:[:SignPdf]
#process_in_background:receipt_file
...
处理器
模块回形针
类SignPdf<处理器
attr_accessor:receipt_id,:风格
S3_CONFIG = YAML.load_file(#{:: Rails.root} /config/s3.yml)[Rails.env]
ORIGAMIDIR =/ruby/1.9.1/gems/origami-1.2.4/lib
高清初始化(文件,选项= {},附件=无)
@file =文件
@current_format = File.extname(@ file.path)
@basename = File.basename(@ file.path,@current_format)
@attachment =附件
结束
高清制作
signPdf(@file)
@文件
结束
结束
结束
开始
需要'折纸'
救援LoadError
$:其中;&其中; ORIGAMIDIR
需要'折纸'
结束
包括折纸
高清signPdf(文件)
certFile中=#{:: Rails.root} /lib/assets/Cert.pem
rsakeyFile =#{:: Rails.root} /lib/assets/pk.pem
密码=o2Receipts
key4pem = File.read rsakeyFile
键=的OpenSSL :: PKEY :: RSA.new key4pem,密码
证书=的OpenSSL :: X509 :: Certificate.new(File.read certFile中)
PDF = PDF.read(文件)
页= pdf.get_page(1)
#添加签名注释(所以它变成可见位置,在PDF文档)
sigannot =注释::小工具:: Signature.new
sigannot.Rect =矩形[:LLX => 89.0,:LLY => 386.0,:URX => 190.0,:URY => 353.0]
page.add_annot(sigannot)
#签署PDF指定键
pdf.sign(证书,密钥,
:方法=> adbe.pkcs7.sha1,
:注释=> sigannot,
:位置=> 葡萄牙,
:触点=> email@email.pt
:原因=> 概念验证
)
#保存生成的文件
pdf.save(file.path)
文件
结束
我身边有这个工作,使用后保存。见我的回答与本主题 href="http://stackoverflow.com/a/12354693/1461972">
I'm inserting a digital signature into a pdf file inside my processor, but keep getting an AWS::S3::ERRORS::Requestimeout
error. What is this timeout? Is there any way i could keep the connection open until the file gets uploaded ?
Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
Here is my code :
model:
...
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
...
Processor
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
I have worked around this, by using the after save. See my answer related to this subject here
这篇关于在S3上回形针处理器超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!