Ruby on rails 回形针S3时间戳插值只差一秒钟?
Rails应用程序使用Ruby on rails 回形针S3时间戳插值只差一秒钟?,ruby-on-rails,amazon-s3,paperclip,Ruby On Rails,Amazon S3,Paperclip,Rails应用程序使用回形针作为存储在S3中并随Cloudfront一起交付的附件时,我遇到了一些麻烦。我已经配置了带有时间戳插值的回形针。一切都按预期在登台环境中工作。但是,在生产环境中,存储的实际文件名使用的时间戳间隔为1秒。我不知道为什么 回形针配置 if configatron.aws.enabled Paperclip::Attachment.default_options[:storage] = :s3 Paperclip::Attachment.default_option
回形针
作为存储在S3
中并随Cloudfront
一起交付的附件时,我遇到了一些麻烦。我已经配置了带有时间戳插值的回形针
。一切都按预期在登台环境中工作。但是,在生产环境中,存储的实际文件名使用的时间戳间隔为1秒。我不知道为什么
回形针配置
if configatron.aws.enabled
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_credentials] = {
access_key_id: configatron.aws.access_key,
secret_access_key: configatron.aws.secret_key
}
Paperclip::Attachment.default_options[:protocol] = 'https'
Paperclip::Attachment.default_options[:bucket] = configatron.aws.bucket
Paperclip::Attachment.default_options[:s3_host_alias] = configatron.aws.cloudfront_host
Paperclip::Attachment.default_options[:url] = ":s3_alias_url"
# Change the default path
Paperclip::Attachment.default_options[:path] = "images/:class/:attachment/:id_partition/:style-:timestamp-:filename"
Paperclip.interpolates(:timestamp) do |attachment, style|
attachment.instance_read(:updated_at).to_i
end
end
示例记录
> alumni = Alumni.last
> alumni.updated_at.to_i
=> 1428719699
> alumni.thumb.url
=> "http://d2kektcjb0ajja.cloudfront.net/images/alumnis/thumbs/000/000/664/original-1428719699-diana-zeng-image.jpg?1428719699"
请注意,在上述IRB
会话中,处的更新时间戳与文件名上的时间戳匹配,这是正确的。但是,实际存储在S3
中的文件是thumb-1428719698-diana-zeng-image.jpg
,请注意时间戳为1秒!这意味着找不到上述URL
这只发生在生产上。在我们的登台环境中,它可以完美地工作。我不知道为什么会发生上述情况
有人能帮忙吗
谢谢
Leonard通过将Rails升级到>=4.2.1解决了这个问题
问题是Rails 4.2.0保留了小数秒,这会导致由于舍入到最近的秒而发生漂移