Skip to content

Downloading attachments with basic auth #442

@bobbrodie

Description

@bobbrodie

@marlinpierce the new convenience methods you've added for attachments are incredibly helpful. There's one more thing I think we might need to consider, which is that default_headers isn't set when using basic auth.

Describe the solution you'd like
I think it would be great to pass basic authentication to the attachment URL without needing to manually setting the headers.

Describe alternatives you've considered
This is a working example of what I've done as an interim solution:

# Find my issue
issue = client.Issue.find('TP-1')

# Get the first attachment
attachment = issue.attachments.first

# Create an authorization header value by base64 encoding my username and
# password (which in my case is an API token)
auth = Base64.strict_encode64("#{client.options[:username]}:#{client.options[:password]}").chomp

# Download
File.open('attachment.png', 'wb') do |output|
  attachment.download_file({ 'Authorization' => "Basic #{auth}" }) do |file|
    IO.copy_stream(file, output)
  end
end

I'm working on going through the issues and writing out the wiki to prepare for the new version so this is something I should be able to take a look at.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementEnhancements to existing features

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions