Uploading attachment files programmatically using SOAP


We are programmatically uploading attachments of size 13MB/19MB, using SOAP to Jira CRs, but it takes indefinite time to upload and fails saying socket timeout error

We compared the time taken to upload on 2 jira instances:

# One jira instance with v5.0.4

# and another jira instance with 3.13.2

below is the table with timings:

||Jira instance||File size||Trial 1||Trial 2||Trial 3||Average time to upload||Programmatically/UI||Jira version||

|Jira Old|993 KB|10.14 s|17.65 s|9.57 s|12.45 s|UI|3.13.2|

|Jira New|993 KB|2.9 s|4.21 s|20.8 s|9.31 s|UI|v5.0.4|

|Jira Old|37 KB|12.4 m|13.6 m|12.3 m|12.76 m|Programmatically|3.13.2|

|Jira New|36 KB|2.43 m|1.95 m|2.48 m|2.29 m|Programmatically|v5.0.4|

below is the SOAP code used to upload the file.




File tmpFile = new File(Log_B2G.zip);

String fileName = tmpFile.getName();

added = jiraSoapObject.addAttachmentsToIssue(token, issueKey, new String { fileName },

new byte { getBytesFromFile(tmpFile) });




private static byte getBytesFromFile(File file) throws IOException {

InputStream is = new FileInputStream(file);

// Get the size of the file

long length = file.length();

// You cannot create an array using a long type.

// It needs to be an int type.

// Before converting to an int type, check

// to ensure that file is not larger than Integer.MAX_VALUE.

if (length < Integer.MAX_VALUE) {

// Create the byte array to hold the data

byte bytes = new byte (int) length ;

// Read in the bytes

int offset = 0;

int numRead = 0;

while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {

offset += numRead;

System.out.println(numRead:+numRead+ t offset:+offset);


// Ensure all the bytes have been read in

if (offset < bytes.length) {

throw new IOException(Could not completely read file + file.getName());


// Close the input stream and return bytes


return bytes;

} else {

System.out.println(File is too large);

return null;




Please confirm with us if this is the best code implementation to upload attachment files for version 5.0.4

And why does it take to upload so long and fails for attachments that are 900KB, because this is a blocker for us to be unable to upload files programmatically.

1 answer

1 accepted

1 vote
Answer accepted

For version 4.0 and above addAttachmentsToIssue has already been deprecated. Please use addBase64EncodedAttachmentsToIssue instead.

Refer to: http://docs.atlassian.com/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/JiraSoapService.html#addBase64EncodedAttachmentsToIssue(java.lang.String, java.lang.String, java.lang.String[], java.lang.String[])

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in United States

Confluence Security Advisory

Good morning Members, Not sure if you are aware. Please read the following: https://www.icloud.com/keynote/0RyJ4VEdNUpjDpGfMhfZx9fEg#Confluence_Security_Advisor More details: https://co...

57 views 1 0
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you