How to write a REST plugin which handles a file upload? Edited


I am trying to write a plugin with REST which uploads a file. All I want now is just to receive a file from client and save it on disk. My code is for now:



import com.sun.jersey.multipart.FormDataParam;

public class RESTService {

public RESTService() {}

@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getMessage(@FormDataParam("file") InputStream uploadedInputStream) throws IOException {

String uploadedFileLocation = "/destination/file.xls";

OutputStreamWriter wr = new FileWriter(new File(uploadedFileLocation));
InputStreamReader input = new InputStreamReader(uploadedInputStream);
char[] buffer = new char[1024 * 4];
long count = 0;
int n = 0;
while (-1 != (n = {
wr.write(buffer, 0, n);
count += n;

String output = "File uploaded to : " + uploadedFileLocation;

return Response.status(200).entity(output).build();

Client sends the file by curl execution:

  curl -D- -u user:pswd -X POST -H "X-Atlassian-Token: no-check" -F "file=@file.xls" http://jira:8080/rest/uploadRestPlugin/1.0/upload

The problem is that, the file saved on disk has got additional headers and a footer:

Content-Disposition: form-data; name="file"; filename="file.xls"
Content-Type: text/plain

[there is the file content]


How could I retreive a file from InputStream without additional info? In text files it isn't a big problem, but other files cannot be edited (like .xls) by cutting them in a simple way.

I use this library in pom:


When I add a parameter: @FormDataParam("file") FormDataContentDisposition formDataContentDisposition I got the error:

[c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: Exception obtaining parameters
com.sun.jersey.api.container.ContainerException: Exception obtaining parameters
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(
Caused by: java.lang.NullPointerException
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(
... 208 more

Trying to use (adding dependency in pom) other plugins for REST technologies like:
- com.sun.jersey.multipart.MultiPart 
- org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput

give always stacktrace:

com.atlassian.util.concurrent.LazyReference$InitializationException: com.sun.jersey.spi.inject.Errors$ErrorMessagesException

Please help me.


1 answer

0 vote

Hi Aleksander - Welcome to the community.

Since your question is development related, you can also try asking this over at: (if you haven't already).

There are a lot of helpful and experienced people over there, so you might get a quicker response.

You can read more about the Developer Community in this article:

Thank you for your reply. I didn't know about forum dedicated for developers. I created a thread there as you suggested.

Sam Hall Community Champion Apr 10, 2017

No problem. Atlassian decided to split, but sadly it's not obvious where people should go to post questions of this nature.

I'd post an answer here as well if I can help, but couldn't in this case.

Someone might reply here too.

Sam Hall Community Champion Apr 10, 2017

Here's a link to the question asked over on the Dev Community, in case people want to follow the trail:

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,316 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot