Skip to content

Commit

Permalink
Merge pull request #2332 from stanhu/sh-add-query-params-google
Browse files Browse the repository at this point in the history
Add query parameter support for fog-google
  • Loading branch information
mshibuya authored Dec 24, 2018
2 parents 02d23a7 + cf21b93 commit 0b2e085
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion carrierwave.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "webmock"
s.add_development_dependency "fog-aws"
s.add_development_dependency "fog-google", "<= 0.1.0"
s.add_development_dependency "fog-google", "~> 1.7.1"
s.add_development_dependency "fog-local"
s.add_development_dependency "fog-rackspace"
s.add_development_dependency "mini_magick", ">= 3.6.0"
Expand Down
15 changes: 13 additions & 2 deletions lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,14 @@ def authenticated_url(options = {})
local_file = local_directory.files.new(:key => path)
expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
case @uploader.fog_credentials[:provider]
when 'AWS'
local_file.url(expire_at, options)
when 'AWS', 'Google'
# Older versions of fog-google do not support options as a parameter
if url_options_supported?(local_file)
local_file.url(expire_at, options)
else
warn "Options hash not supported in #{local_file.class}. You may need to upgrade your Fog provider."
local_file.url(expire_at)
end
when 'Rackspace'
connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options)
when 'OpenStack'
Expand Down Expand Up @@ -487,6 +493,11 @@ def read_source_file(file_body)
file_body.close
end
end

def url_options_supported?(local_file)
parameters = file.method(:url).parameters
parameters.count == 2 && parameters[1].include?(:options)
end
end

end # Fog
Expand Down
2 changes: 1 addition & 1 deletion spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end

it "should handle query params" do
if @provider == 'AWS' && !Fog.mocking?
if ['AWS', 'Google'].include?(@provider) && !Fog.mocking?
headers = Excon.get(@fog_file.url(:query => {"response-content-disposition" => "attachment"})).headers
expect(headers["Content-Disposition"]).to eq("attachment")
end
Expand Down

0 comments on commit 0b2e085

Please sign in to comment.