我在一个使用Paperclip的Rails应用程序上遇到了相当大的麻烦,因为它的附件存储在S3中,并与Cloudfront一起交付。我已经用时间戳内插配置了Paperclip。一切都像预期的那样在准备环境上工作。但是,在生产中,实际存储的文件名使用的时间戳是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会话中,updated_at时间戳与filename上的时间戳匹配,这是正确的。但是,实际存储在S3中的文件是thumb-1428719698-diana-zeng-image.jpg,请注意时间戳是1秒!这意味着找不到上面的URL。
这只会在生产中发生。在我们的舞台环境中,它工作得很完美。我不知道为什么会发生上述情况。
有人能帮忙吗?
谢谢!
伦纳德
发布于 2015-04-13 12:30:13
通过将Rails升级到>= 4.2.1解决。
问题是Rails 4.2.0保留小数秒,由于舍入到最近的秒,导致漂移发生。
https://stackoverflow.com/questions/29573550
复制相似问题