I am using Jersey to upload file. I defined the method:
@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Collection<Message> uploadImage(@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) throws IOException {
}
And invoke the call from Jersey Client for testing:
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
String url = "http://localhost:8080/API/api/images/upload/150";
File f = new File("C:/Pictures/1360_435x300.jpg");
FormDataMultiPart form = new FormDataMultiPart();
form.bodyPart(new FileDataBodyPart("thumbnail", f));
String s = client.resource(url).type(MediaType.MULTIPART_FORM_DATA).accept(MediaType.APPLICATION_JSON).post(String.class, form);
However, I get:
SEVERE: Missing dependency for method public java.util.Collection ImageResource.uploadImage(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 1
what is wrong?
Make sure all libs are the same version (e.g. 1.13), and don't forget to add mimepull.jar and jersey-multipart.jar as well.
You need to add Maven dependencies related to Multipart handling.
If you need check http://mvnrepository.com/ for the versions of the dependencies for your Jersey version.
Thanks @john 4d5 People please ensure that all the jars version are in sync You can find all the possible jars here. :) https://maven.java.net/index.html#welcome