Closed ssbarnea closed 10 years ago
Just a heads up that there's a Rally tag forum on Stackoverflow - https://stackoverflow.com/questions/tagged/rally where Rally developers frequently answer toolkit usage questions similar to this one. It helps maintain focus on GitHub issues for identified bugs in the toolkit.
This Gist:
https://gist.github.com/markwilliams970/6a1380f4949c12a678a1
contains an example of saving attachment content that should help you, but the core of it is to Base64 decode the content string, and write the resulting bytes to a file:
require 'base64'
def save_attachment(this_attachment)
file_name = this_attachment.Name
this_attachment_content = this_attachment.Content
if this_attachment_content == nil
# Yes it is possible to have an attachment with no content
extension = ".empty"
file_data = File.new(file_name + extension, "wb")
else
this_attachment_content.read
this_content = this_attachment_content.Content
file_data = File.new(file_name, "wb")
file_data.syswrite(Base64.decode64(this_content))
end
puts " Saved filename=#{file_name} Size=#{this_attachment.Size}\n"
file_data.close
end
It seems that this can be decoded as a base64 but still, this is at least a bug in the documentation if not even in the API, that it does not provide the content in binary format.
The API is working as expected. I'll check with the toolkit author to see about getting a similar example included in the examples directory in the Github repo.
The AP is working, what I was trying to say is that is not documented. The simple fact that both of us had to google around (and use the debugger in my case) just to discover how to get the content of the attachment is clearly a "design bug".
Just to confirm this bug, I observed somebody else raising a ticket regarding making attachment API easier to use. See issue #26
Thanks for the feedback. In general the API toolkit docs are meant to supplement, but not replace, the full webservices API docs, https://rally1.rallydev.com/slm/doc/webservice. The documentation for the AttachmentContent object: https://rally1.rallydev.com/slm/doc/webservice/objectModel.sp#AttachmentContent indicates how to traverse the object model to find the needed data, as well as its type (base64Binary).
Also for what it's worth - the ruby toolkit author would seem to agree with you that additional methods to help with getting attachments would be desirable enhancements. Issue #26 as you reference above was created by the toolkit author himself :)
It seems that the body of the attachment is inside Attachment.Content.content but this is an Unicode string which is encoded.
It seems that there is no documentation regarding how to save the body of the attachment in a binary file.