3

I am using Jersey to build a REST service to upload a file. My method starts like this:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@Path("/upload")
public String upload(
    @FormDataParam("one") String one,
    @FormDataParam("two") String two,
    @FormDataParam("file") InputStream file) {

When I am posting a request for this resource with "one", "two" and "file" form fields, I get the entire payload, including the binary file data and multipart boundaries, in the variable "one", instead of each variable getting its respective value from the form fields.

What is going wrong here?

EDIT: For client, I have used this HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

    <form method="post" action="/upload"
        enctype="multipart/form-data">
        One: <input type="text" name="one" /> 
        Two: <input type="text" name="two" /> 
        File: <input type="file" name="file" />
        <input type="submit" name="Submit" />
    </form>
</body>
</html>

I have also tried using Postman REST client for Chrome.

Update 1: As the person who asked the problem is not updating, I'll do the honors of adding data which may help in reproducing the problem -

Postman Call

Java method

Debugging the above java method

Saurabh Gupta
  • 363
  • 3
  • 6
  • 17
Pranav Pal
  • 275
  • 6
  • 18

0 Answers0