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

Headers for download by url #2006

Merged

Conversation

mendab1e
Copy link
Contributor

Hi. I use CarrierWave in my project, where I need to download some images using authorization token in header. I haven't found support of sending custom headers in request, so I've implement it in this pull request.

Here is the example of usage:

class Content
  extend CarrierWave::Mount
  mount_uploader :image, ImageUploader
end

c = Content.new
c.remote_image_request_header = {'Authorization' => 'Bearer QWERTY'}
c.remote_image_url = 'http://example.com/1.jpg'

@@ -35,7 +36,10 @@ def http?

def file
if @file.blank?
@file = Kernel.open(@uri.to_s, "User-Agent" => "CarrierWave/#{CarrierWave::VERSION}")
headers = @remote_headers.
merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using reverse_merge can be useful when a user want to set specific User-Agent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshibuya Good point. I've pushed new commit with reverse_merge.

@mshibuya mshibuya merged commit 5367a63 into carrierwaveuploader:master Sep 19, 2016
@mshibuya
Copy link
Member

Nice work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants