1
votes

Below is the signature of my webservice method that accepts attachment with it's content-type = multipart/form-data

@POST  @Path("/saveimg")    
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response saveAttachment( @FormDataParam("files") InputStream fileInputStream,
             @FormDataParam("files") FormDataContentDisposition contentDispositionHeader) {

I got the following error:

SEVERE: A message body reader for Java class com.sun.jersey.core.header.FormDataContentDisposition, and Java type class com.sun.jersey.core.header.FormDataContentDisposition, and MIME media type multipart/form-data; boundary=----WebKitFormBoundaryiNkfu0uRssIuZMPX 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

2
When I changed the consumer content-type to @Consumes("application/x-www-form-urlencoded") the above error log disappears but server 415 ( Un Supported Media Type) persists. The request sent has content-type multipart/form-data including boundary along with mulitipart/form-data. - Yergalem
Check my answer in a previous post, it might help you. stackoverflow.com/questions/38361880/… - Wilder Valera
For some reason, I'm not using Maven. Can you tell me what is missing? - Yergalem
it seems you need to have the jar for multipart. Are you using glassfish libraries? - Wilder Valera

2 Answers

1
votes

try to remove FormDataContentDisposition, I removed it and now I don't have 415 error... but I have to find an other way to get the information needed.

my file here:@FormDataParam("file") InputStream fileStream.

I tried to read file like that:

final Reader reader = new InputStreamReader(fileStream); String text = CharStreams.toString(reader);

but not my final solution... i'm looking for other solution... hope I could be helpfully.

0
votes

However late answered, I solved my problem by using Jersey 2 Framework. Jersey version 1 didn't work for me. Apart from that, the required libraries are:

    jersey-media-multipart-2.25

    mimepull-1.9.7

Note: I used jackson provider - jersey-media-json-jackson-2.5.1

Easily, it's possible to test it from Chrome POSTMAN

   >> method - PUT, POST
   >> Give Path(URL) of your resource method
   >> Body -- form-data  
   >> key -- should match with @@FormDataParam argument
   >> Choose File -> browse but make sure it's **File** type not Text
   >> Yeah, Hit SEND