Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:19:23+00:00 2026-06-07T16:19:23+00:00

We’re in the process of porting our .NET Rally code from SOAP to the

  • 0

We’re in the process of porting our .NET Rally code from SOAP to the REST .NET API. So far so good, the REST API seems to be faster and is easier to use since there’s no WSDL to break each time the work product custom fields change in the Rally Workspace.

I’m having trouble with one thing though as we try to replicate the ability to upload attachments. We’re following a very similar procedure as to the one outlined in this posting:

Rally SOAP API – How do I add an attachment to a Hierarchical Requirement

Whereby the image is read into a System.Drawing.Image. We use the ImageToByteArray function to convert the image to a byte array which then gets assigned to the AttachmentContent, which is created first.

Then, the Attachment gets created, and wired up to both AttachmentContent, and the HierarchicalRequirement.

All of the creation events work great. The content object gets created fine. Then the new attachment called “Image.png” gets created and linked to the Story. But when I download the resulting attachment from Rally, Image.png has zero bytes! I’ve tried this with different images, JPEG’s, PNG’s, etc. all with the same results.

An excerpt of the code showing our process is included below. Is there something obvious that I’m missing? Thanks in advance.

    // .... Read content into a System.Drawing.Image called imageObject ....

    // Convert Image to byte array
    byte[] imageBytes = ImageToByteArray(imageObject, System.Drawing.Imaging.ImageFormat.Png);
    var imageLength = imageBytes.Length;

    // AttachmentContent
    DynamicJsonObject attachmentContent = new DynamicJsonObject();
    attachmentContent["Content"] = imageBytes ;

    CreateResult cr = restApi.Create("AttachmentContent", myAttachmentContent);
    String contentRef = cr.Reference;
    Console.WriteLine("Created: " + contentRef);

    // Set up attachment
    DynamicJsonObject newAttachment = new DynamicJsonObject();
    newAttachment["Artifact"] = story;
    newAttachment["Content"] = attachmentContent;
    newAttachment["Name"] = "Image.png";
    newAttachment["ContentType"] = "image/png";
    newAttachment["Size"] = imageLength;
    newAttachment["User"] = user;


    // Create the attachment in Rally
    cr = restApi.Create("Attachment", newAttachment);

    String attachRef = cr.Reference;
    Console.WriteLine("Created: " + attachRef);

}

public static byte[] ImageToByteArray(Image image, System.Drawing.Imaging.ImageFormat format)
{
    using (MemoryStream ms = new MemoryStream())
    {
        image.Save(ms, format);

        // Convert Image to byte[]                
        byte[] imageBytes = ms.ToArray();
        return imageBytes;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:19:25+00:00Added an answer on June 7, 2026 at 4:19 pm

    This issue also had me puzzled for a while – finally sorted it out about a week ago.

    Two observations:

    1. While Rally’s SOAP API will serialize the byte array into a Base64 string behind the scenes, REST doesn’t do this step for you and will expect a Base64-formatted String to be passed as the Content attribute for the AttachmentContent object.
    2. System.Drawing.Image.Length as shown in your example won’t provide the correct length that Rally’s WSAPI is expecting. You need to pass the length of the Base64-formatted string after being converted back to a regular String. This is also the same as the length of the byte array.

    I’m including a code sample to illustrate:

    // System Libraries
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing.Imaging;
    using System.Drawing;
    using System.IO;
    using System.Web;
    
    // Rally REST API Libraries
    using Rally.RestApi;
    using Rally.RestApi.Response;
    
    namespace RestExample_CreateAttachment
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Set user parameters
                String userName = "user@company.com";
                String userPassword = "password";
    
                // Set Rally parameters
                String rallyURL = "https://rally1.rallydev.com";
                String rallyWSAPIVersion = "1.36";
    
                //Initialize the REST API
                RallyRestApi restApi;
                restApi = new RallyRestApi(userName,
                                           userPassword,
                                           rallyURL,
                                           rallyWSAPIVersion);
    
                // Create Request for User
                Request userRequest = new Request("user");
                userRequest.Fetch = new List<string>()
                    {
                        "UserName",
                        "Subscription",
                        "DisplayName",
                    };
    
                // Add a Query to the Request
                userRequest.Query = new Query("UserName",Query.Operator.Equals,userName);
    
                // Query Rally
                QueryResult queryUserResults = restApi.Query(userRequest);
    
                // Grab resulting User object and Ref
                DynamicJsonObject myUser = new DynamicJsonObject();
                myUser = queryUserResults.Results.First();
                String myUserRef = myUser["_ref"];
    
                //Set our Workspace and Project scopings
                String workspaceRef = "/workspace/12345678910";
                String projectRef = "/project/12345678911";
                bool projectScopingUp = false;
                bool projectScopingDown = true;
    
                // Find User Story that we want to add attachment to
    
                // Tee up Story Request
                Request storyRequest = new Request("hierarchicalrequirement");
                storyRequest.Workspace = workspaceRef;
                storyRequest.Project = projectRef;
                storyRequest.ProjectScopeDown = projectScopingDown;
                storyRequest.ProjectScopeUp = projectScopingUp;
    
                // Fields to Fetch
                storyRequest.Fetch = new List<string>()
                    {
                        "Name",
                        "FormattedID"
                    };
    
                // Add a query
                storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, "US43");
    
                // Query Rally for the Story
                QueryResult queryResult = restApi.Query(storyRequest);
    
                // Pull reference off of Story fetch
                var storyObject = queryResult.Results.First();
                String storyReference = storyObject["_ref"];
    
                // Read In Image Content
                String imageFilePath = "C:\\Users\\username\\";
                String imageFileName = "image1.png";
                String fullImageFile = imageFilePath + imageFileName;
                Image myImage = Image.FromFile(fullImageFile);
    
                // Get length from Image.Length attribute - don't use this in REST though
                // REST expects the length of the image in number of bytes as converted to a byte array
                var imageFileLength = new FileInfo(fullImageFile).Length;
                Console.WriteLine("Image File Length from System.Drawing.Image: " + imageFileLength);
    
                // Convert Image to Base64 format
                string imageBase64String = ImageToBase64(myImage, System.Drawing.Imaging.ImageFormat.Png);           
    
                // Length calculated from Base64String converted back
                var imageNumberBytes = Convert.FromBase64String(imageBase64String).Length;
    
                // This differs from just the Length of the Base 64 String!
                Console.WriteLine("Image File Length from Convert.FromBase64String: " + imageNumberBytes);
    
                // DynamicJSONObject for AttachmentContent
                DynamicJsonObject myAttachmentContent = new DynamicJsonObject();
                myAttachmentContent["Content"] = imageBase64String;
    
                try
                {
                    CreateResult myAttachmentContentCreateResult = restApi.Create("AttachmentContent", myAttachmentContent);
                    String myAttachmentContentRef = myAttachmentContentCreateResult.Reference;
                    Console.WriteLine("Created: " + myAttachmentContentRef);
    
                    // DynamicJSONObject for Attachment Container
                    DynamicJsonObject myAttachment = new DynamicJsonObject();
                    myAttachment["Artifact"] = storyReference;
                    myAttachment["Content"] = myAttachmentContentRef;
                    myAttachment["Name"] = "AttachmentFromREST.png";
                    myAttachment["Description"] = "Attachment Desc";
                    myAttachment["ContentType"] = "image/png";
                    myAttachment["Size"] = imageNumberBytes;
                    myAttachment["User"] = myUserRef;
    
                    CreateResult myAttachmentCreateResult = restApi.Create("Attachment", myAttachment);
    
                    List<string> createErrors = myAttachmentContentCreateResult.Errors;
                    for (int i = 0; i < createErrors.Count; i++)
                    {
                        Console.WriteLine(createErrors[i]);
                    }
    
                    String myAttachmentRef = myAttachmentCreateResult.Reference;
                    Console.WriteLine("Created: " + myAttachmentRef);
    
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unhandled exception occurred: " + e.StackTrace);
                    Console.WriteLine(e.Message);
                }
            }
    
            // Converts image to Base 64 Encoded string
            public static string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    image.Save(ms, format);
                    // Convert Image to byte[]                
                    byte[] imageBytes = ms.ToArray();
    
                    // Convert byte[] to Base64 String
                    string base64String = Convert.ToBase64String(imageBytes);
    
                    return base64String;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.