Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 回形针S3时间戳插值只差一秒钟?_Ruby On Rails_Amazon S3_Paperclip - Fatal编程技术网

Ruby on rails 回形针S3时间戳插值只差一秒钟?

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

Rails应用程序使用
回形针
作为存储在
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保留了小数秒,这会导致由于舍入到最近的秒而发生漂移