Commit 808d2950 by Matt Hawkins Committed by Jon Yurek

added method to generate an time expiring url

(cherry picked from commit 61dbcb3e36c0bc9742d045dd1e54f846043a1569)
parent 3f938287
...@@ -160,6 +160,10 @@ module Paperclip ...@@ -160,6 +160,10 @@ module Paperclip
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
end end
......
...@@ -97,6 +97,33 @@ class StorageTest < Test::Unit::TestCase ...@@ -97,6 +97,33 @@ class StorageTest < Test::Unit::TestCase
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
AWS::S3::Base.stubs(:establish_connection!) AWS::S3::Base.stubs(:establish_connection!)
......
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