java - Status Code 415: No MessageBodyReader Found for multipart/form-data, FormDataMultiPart -



java - Status Code 415: No MessageBodyReader Found for multipart/form-data, FormDataMultiPart -

i'm running problem posting multipart/form-data restful web service i've made. trying upload media files (images, video, audio) via restful web service. googled around find best way , found posting multipart/form-data best solution.

the problem when post multipart/form-data error message in tomcat server:

severe messagebodyreader not found media type=multipart/form-data; boundary=----webkitformboundarytg7uvlcyj3lsbpqe, type=class org.glassfish.jersey.media.multipart.formdatamultipart, generictype=class org.glassfish.jersey.media.multipart.formdatamultipart.

i did seek looking on stackoverflow find reply , problem seemed mimepull.jar missing many people. checked create sure mimepull.jar in classpath , indeed is, not issue. @ point i'm stuck.

here dependencies in pom.xml:

<dependencies> <dependency> <groupid>org.eclipse.persistence</groupid> <artifactid>eclipselink</artifactid> <version>2.5.1</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>6.0</version> <scope>provided</scope> </dependency> <dependency> <groupid>org.glassfish.jersey.core</groupid> <artifactid>jersey-server</artifactid> <version>2.12</version> </dependency> <dependency> <groupid>org.glassfish.jersey.containers</groupid> <artifactid>jersey-container-servlet-core</artifactid> <version>2.12</version> </dependency> <dependency> <groupid>javax.ws.rs</groupid> <artifactid>javax.ws.rs-api</artifactid> <version>2.0</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.jaxrs</groupid> <artifactid>jackson-jaxrs-json-provider</artifactid> <version>2.4.2</version> </dependency> <dependency> <groupid>org.glassfish.jersey.media</groupid> <artifactid>jersey-media-json-jackson</artifactid> <version>2.12</version> </dependency> <dependency> <groupid>org.glassfish.jersey.media</groupid> <artifactid>jersey-media-multipart</artifactid> <version>2.12</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-core</artifactid> <version>2.4.2</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</artifactid> <version>2.4.2</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-annotations</artifactid> <version>2.4.2</version> </dependency> </dependencies>

here relevant backend code handles multipart/form-data posts:

@post @path("media") @consumes(mediatype.multipart_form_data) @produces(mediatype.application_json) public response uploadfile(formdatamultipart form ) { formdatabodypart filepart = form.getfield("file"); contentdisposition headeroffilepart = filepart.getcontentdisposition(); inputstream uploadedinputstream = filepart.getvalueas(inputstream.class); string uploadedfilelocation = "c:\\surveymedia\\media" + headeroffilepart.getfilename(); seek { savefile(uploadedinputstream, uploadedfilelocation); } grab (exception e) { homecoming response.status(400).entity(e.getcause()).build(); } string output = "file uploaded to: " + uploadedfilelocation; homecoming response.status(200).entity(output).build(); }

lastly here test page made test sending files backend:

<html> <head> <title></title> </head> <body> <h1>file upload jersey</h1> <form action="/rest/surveys/media" method="post" enctype="multipart/form-data"> <p> select file : <input type="file" name="file" size="45" /> </p> <input type="submit" value="upload it" /> </form> </body> </html>

let me know if need more information. in advance help!

i ran similar issue when implementing file uploader via jersey, ended taking different approach method's parameters inputstream , formdatacontentdisposition object.

here's example; perhaps work you:

@post @consumes(mediatype.multipart_form_data) @produces({mediatype.application_json}) public response uploadfile( @formdataparam("file") inputstream uploadedinputstream, @formdataparam("file") formdatacontentdisposition filedetail) throws exception { string filename = filedetail.getfilename(); string uploadedfilelocation = "c:\\surveymedia\\media" + filename; seek { savefile(uploadedinputstream, uploadedfilelocation); } catch(exception e){ homecoming response.status(400).entity(e.getcause()).build(); } string output = "file uploaded to: " + uploadedfilelocation; homecoming response.status(200).entity(output).build(); }

java rest maven tomcat jersey

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -