【问题标题】:uploading video to s3 with paperclip使用回形针将视频上传到 s3
【发布时间】:2012-10-08 18:04:20
【问题描述】:

您好,我正在尝试将视频上传到 s3 并使用 flowplayer 显示它

我的 flowplayer 崩溃了,因为数字是添加在视频 src 的 url 后面的

<div class="flowplayer" style="width: 624px; height: 260px; ">
   <video src="http://s3-ap-southeast-1.amazonaws.com/psyched-sg-store/624x260.mp4?1350552718"></video>
</div>

这会破坏我的 flowplayer ,但是在查看源代码后单击链接会将我带到视频

<div class="flowplayer" style="width: 624px; height: 260px; ">
   <video src="http://s3-ap-southeast-1.amazonaws.com/psyched-sg-store/624x260.mp4"></video>
</div>

这行得通

我是这样设置回形针的

# /config/initializer/s3.rb
# if you're using sg buckets
Paperclip.interpolates(:s3_sg_url) { |attachment, style|
   "#{attachment.s3_protocol}//s3-ap-southeast-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/},
   "")}"
   }

在我的模型中..

  has_attached_file :attached_video,:storage => :s3,
       :s3_credentials => "#{Rails.root}/config/s3.yml",
       :path => "/:filename",
       :url  => ":s3_sg_url"

       def attached_video_url
           if attached_video.file?
            attached_video.url
          else
            nil
        end    
      end

我还设置了我的 s3.yml

development:
  bucket: psyched-sg-store
  access_key_id: xx
  secret_access_key: xx
test:
  bucket: psyched-sg-store
  access_key_id: xx
  secret_access_key: x
production:
  bucket: psyched-sg-store
  access_key_id: xx
  secret_access_key: xx

怎么了?为什么url后面会出现数字?

【问题讨论】:

    标签: ruby-on-rails amazon-s3 paperclip


    【解决方案1】:

    这些数字是反缓存时间戳。如果您想摆脱它们,请将 :use_timestamp =&gt; false 添加到模型的附件设置中,如下所示:

    has_attached_file :attached_video,:storage => :s3,
           :s3_credentials => "#{Rails.root}/config/s3.yml",
           :path => "/:filename",
           :url  => ":s3_sg_url",
           :use_timestamp => false
    

    【讨论】:

      猜你喜欢
      • 2013-10-13
      • 2013-10-16
      • 2016-11-19
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      相关资源
      最近更新 更多