sumoheavy / jira-ruby

A Ruby gem for the JIRA REST API
MIT License
654 stars 412 forks source link

File attachment silently fails #402

Closed JeanFred closed 4 months ago

JeanFred commented 1 year ago

I am trying to attach a file using the following code:

ticket_id = "ABC-123"
filename = "/path/to/file"
puts "Uploading file #{filename} to Jira ticket #{ticket_id}"
options = {
    :site            => 'https://jira.x.y.z',
    :context_path    => '',
    :default_headers => {'Authorization' => "Bearer #{API_TOKEN}"},
    :auth_type       => :basic
}
client = JIRA::Client.new(options)
issue = client.Issue.find(ticket_id)
puts "Found issue #{issue.fields['summary']}"
attachment = issue.attachments.build
attachment.save('file': filename)

This results in the following output:

Uploading file /path/to/file to Jira ticket ABC-123
Found issue "My important issue"
/vendor/bundle/ruby/2.7.0/gems/jira-ruby-2.3.0/lib/jira/resource/attachment.rb:27: warning: constant ::UploadIO is deprecated

And no file is actually attached to the ticket.

I used to do by calling another Python script from Ruby, so things should be fine on the account/token front.

marlinpierce commented 10 months ago

I had a problem uploading attachments using default headers.

See gitlab issue https://github.com/sumoheavy/jira-ruby/issues/416

bobbrodie commented 4 months ago

Related PR was merged and will be in the next release, so I'll go ahead and close this.