2

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?

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
Dejell
  • 13,947
  • 40
  • 146
  • 229

3 Answers3

4

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.

john 4d5
  • 731
  • 6
  • 11
  • 5
    To anyone who stumbles here from google: If the above doesn't work out, make sure you've got `@Consumes(MediaType.MULTIPART_FORM_DATA)`. See http://stackoverflow.com/questions/16831443 – yshavit Nov 22 '13 at 22:51
  • @john, You are really genius... Because no one mention `mimepull.jar` in Stack overflow answers. – Pugal Oct 13 '20 at 11:43
  • @yshavit, Your comment also have an additional point for my problem. – Pugal Oct 13 '20 at 11:44
0

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

zeta
  • 1
0

You need to add Maven dependencies related to Multipart handling.

    <dependency> <!-- choose your version -->
        <groupId>org.jvnet</groupId>
        <artifactId>mimepull</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency> <!-- choose your version -->
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.18.1</version>
    </dependency>

If you need check http://mvnrepository.com/ for the versions of the dependencies for your Jersey version.