Uploading attachment files programmatically using SOAP

Atlassian

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.

{code}

...

...

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

is.close();

return bytes;

} else {

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

return null;

}

}

{code}

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

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Hipchat

Moving from Hipchat to Stride? Here’s what you’ll love

Heya, Hipchat friends! We’re so happy you’re checking out   Stride. Whether you know it or not, you have been instrumental in making Stride come to life. Every feature, design, and functionality...

68 views 2 6
Read article

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