Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can't upload binary file to Rest Controler

Jacek Tomczak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 19, 2023

HI Everyone
I'm developing a plugin that should be able to recive binary files and store it somre whare in data dir at JIRA_HOME 

my currnet code

@AnonymousAllowed
@PublicApi
@Produces(MediaType.APPLICATION_JSON)
@POST
@Path("/uploadFile")
@Consumes({"multipart/form-data", "multipart/mixed"})
// @XsrfProtectionExcluded
public Response uploadFile(
@RequestPart("file") CommonsMultipartFile multipartFile)
throws IOException {

return Response.ok("{'success':'1'}").build();
}

pom

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>


command to upload: 

curl -v http://localhost:8080/rest/bigatt/1.0/api/uploadFile -H "X-Atlassian-Token: no-check" -X POST -F "file=@1MB"

 

and when trying to upload it i get error:uploadFile [c.s.j.spi.container.ContainerRequest] A message body reader for Java class org.springframework.web.multipart.commons.CommonsMultipartFile, and Java type class org.springframework.web.multipart.commons.CommonsMultipartFile, and MIME media type multipart/form-data; boundary=------------------------c85315be318a14ec was not found.
The registered message body readers compatible with the MIME media type are:
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

in postman I have Unsupported Media Type Error


What i'm missing ?

1 answer

0 votes
Jacek Tomczak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 20, 2023

After looking through jira src code i found solution/workaround ant it looks like this

@POST
@Produces({"application/json"})
@Path("/uploadFile2")
@ExperimentalApi
@Consumes(MediaType.WILDCARD)
public Response uploadFile2(@Context HttpServletRequest request, @QueryParam("file") String fileName) throws IOException {
int size=request.getContentLength();
FileUploadUtil.saveFile(fileName,request.getInputStream());

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20
TAGS
AUG Leaders

Atlassian Community Events