Commit 808d2950 by Matt Hawkins Committed by Jon Yurek

added method to generate an time expiring url

(cherry picked from commit 61dbcb3e36c0bc9742d045dd1e54f846043a1569)
parent 3f938287
...@@ -159,6 +159,10 @@ module Paperclip ...@@ -159,6 +159,10 @@ module Paperclip
"#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}" "#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
end end
end end
def expiring_url(time = 3600)
AWS::S3::S3Object.url_for(path, bucket_name, :expires_in => time )
end
def bucket_name def bucket_name
@bucket @bucket
......
...@@ -96,6 +96,33 @@ class StorageTest < Test::Unit::TestCase ...@@ -96,6 +96,33 @@ class StorageTest < Test::Unit::TestCase
assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url
end end
end end
context "Generating a url with an expiration" do
setup do
AWS::S3::Base.stubs(:establish_connection!)
rebuild_model :storage => :s3,
:s3_credentials => {
:production => { :bucket => "prod_bucket" },
:development => { :bucket => "dev_bucket" }
},
:s3_host_alias => "something.something.com",
:path => ":attachment/:basename.:extension",
:url => ":s3_alias_url"
rails_env("production")
@dummy = Dummy.new
@dummy.avatar = StringIO.new(".")
AWS::S3::S3Object.expects(:url_for).with("avatars/stringio.txt", "prod_bucket", { :expires_in => 3600 })
@dummy.avatar.expiring_url
end
should "should succeed" do
assert true
end
end
context "Parsing S3 credentials with a bucket in them" do context "Parsing S3 credentials with a bucket in them" do
setup do setup do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment