Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support virtual_host in presigned_url when using s3_host_alias #124

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ def self.extended(base)

def expiring_url(time = 3600, style_name = default_style)
if path(style_name)
base_options = { expires_in: time }
base_options = {
expires_in: time,
virtual_host: @options[:url] == ":s3_alias_url" && @options[:s3_host_alias] != nil
}
s3_object(style_name).presigned_url(
:get,
base_options.merge(s3_url_options)
Expand Down
8 changes: 5 additions & 3 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def counter
object = double
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:presigned_url).with(:get, { expires_in: 3600 })
expect(object).to receive(:presigned_url).with(:get, { expires_in: 3600, virtual_host: true })
@dummy.avatar.expiring_url
end
end
Expand All @@ -761,6 +761,7 @@ def counter
{
expires_in: 3600,
response_content_disposition: "inline",
virtual_host: true
},
)
@dummy.avatar.expiring_url
Expand Down Expand Up @@ -789,6 +790,7 @@ def counter
{
expires_in: 3600,
response_content_type: "image/png",
virtual_host: true
},
)
@dummy.avatar.expiring_url
Expand Down Expand Up @@ -837,14 +839,14 @@ def counter
it "generates a url for the thumb" do
object = double
allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(object)
expect(object).to receive(:presigned_url).with(:get, { expires_in: 1800 })
expect(object).to receive(:presigned_url).with(:get, { expires_in: 1800, virtual_host: true })
@dummy.avatar.expiring_url(1800, :thumb)
end

it "generates a url for the default style" do
object = double
allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(object)
expect(object).to receive(:presigned_url).with(:get, { expires_in: 1800 })
expect(object).to receive(:presigned_url).with(:get, { expires_in: 1800, virtual_host: true })
@dummy.avatar.expiring_url(1800)
end
end
Expand Down