How to solve this error: org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

srinivasan radhakrishnan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2013

Hi,

I need to attach the file to "On demand JIRA" issue by REST API. I have set media type is "multipart/formdata" and header set as "X-Atlassian-Token:nocheck". When i run the REST API i got this issue

org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

I could i solve this problem in my on demand JIRA.

5 answers

1 accepted

0 votes
Answer accepted
srinivasan radhakrishnan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2013

Now i am able to attach a file to JIRA issue attachment section by changing the below code block

var filecontent = new ByteArrayContent(System.IO.File.ReadAllBytes("C:\\Users\\XXXX\\Desktop\\Sample.xlsx"));
            var content = new MultipartContent("form-data", "AAAA");
            content.Headers.Add("X-Atlassian-Token", "nocheck");
            content.Headers.Add("charset", "UTF-8");

            filecontent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
            {
                Name="\"file\"",
                FileName = "Attachment.xlsx"
            };

            filecontent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            content.Add(filecontent);

0 votes
srinivasan radhakrishnan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013

Please find my remaining C# code blocks for file upload in On demand jira

try
            {
                client.PostAsync("https://{server name}.atlassian.net/rest/api/2/issue/TEST-1/attachments", content).ContinueWith(requesTask =>
                {
                    try
                    {
                        HttpResponseMessage response = requesTask.Result;
                        if (response.StatusCode == "OK")
                        {
                            Console.WriteLine(" Attached .");
                        }
                        else
                        {
                        }
                    }
                    catch (Exception exception)
                    {
                    }
                });


            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.StackTrace.ToString());
                Console.ReadLine();
            }

            Console.ReadKey();
        }



}

Json Response is 200,Ok but Json returns object is [] - please use the below command in immediate window

string s=response.Content.ReadAsStringAsync().Result;

Result - "[]"

Please highlight my mistakes in the code blocks.

0 votes
srinivasan radhakrishnan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013

Please find my remaining C# code blocks for file upload in On demand jira

try
            {
                client.PostAsync("https://{server name}.atlassian.net/rest/api/2/issue/TEST-1/attachments", content).ContinueWith(requesTask =>
                {
                    try
                    {
                        HttpResponseMessage response = requesTask.Result;
                        if (response.StatusCode == "OK")
                        {
                            Console.WriteLine(" Attached .");
                        }
                        else
                        {
                        }
                    }
                    catch (Exception exception)
                    {
                    }
                });


            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.StackTrace.ToString());
                Console.ReadLine();
            }

            Console.ReadKey();
        }


}




Json Response is 200,Ok but Json returns object is [] - please use this in immediate window

string s=response.Content.ReadAsStringAsync().Result;

Result - "[]"

Please highlight my mistakes in the code blocks.

0 votes
srinivasan radhakrishnan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013

Hi All,

Now the FileUploadException is solved.

I have used the below code to attach a file to "On demand JIRA",the response is 200, OK but Json return object is []

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using System.Json;
using System.Web.Script.Serialization;
using System.Net;

namespace JiraAttachements
{
    class Class1
    {
        public void AddAttachment()
        {
            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
            client.DefaultRequestHeaders.ExpectContinue = false;
            client.Timeout = TimeSpan.FromMinutes(90);
            byte[] crdential = UTF8Encoding.UTF8.GetBytes("wwww:yyyy");
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(crdential));
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var filecontent = new ByteArrayContent(System.IO.File.ReadAllBytes("C:\\Users\\xxx\\Desktop\\Keys.txt"));

            var content = new MultipartFormDataContent("AA");

            content.Headers.Add("X-Atlassian-Token", "nocheck");
            content.Headers.Add("charset", "UTF-8");

            content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
            {
                Name="\"file\"",
                FileName = "C:\\Users\\xxx\\Desktop\\Keys.txt"
            };

            content.Add(filecontent);

please find the remaining code block in next comment


0 votes
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2013

Google says this to me - http://stackoverflow.com/questions/13240664/how-to-set-a-boundary-on-a-multipart-form-data-request-while-using-jquery-ajax-f

(it says to set the contentType to false while making the ajax query from javascript. You need to find the quilvalent in the language you are writing the code)

Suggest an answer

Log in or Sign up to answer