12

I have a RESTeasy-based REST web service (see below). I'm trying to use the google REST client to execute a request to test my service, but I'm unsure as to how the request should be setup.

I'm not sure how to send the byte[] as a param (filedata).
Any ideas on how to test this?

I get the following exception:

java.io.IOException: Unable to get boundary for multipart

with

request:
-content-type=multipart/form-data
-form params:
test=testvalue

Rest method:

@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Response create(@MultipartForm FileUploadForm form) {
   System.out.println("form=" + form.getTest());
   return null;
}

FileUploadForm Pojo:

import javax.ws.rs.FormParam;
import org.jboss.resteasy.annotations.providers.multipart.PartType;

public class FileUploadForm {
    private byte[] filedata;
    private String test;

    public FileUploadForm() {}

    public byte[] getFileData() {
        return filedata;
    }

    @FormParam("filedata")
    @PartType("application/octet-stream")
    public void setFileData(final byte[] filedata) {
        this.filedata = filedata;
    }

    public String getTest() {
        return test;
    }

    @FormParam("test")
    @PartType("application/json")
    public void setTest(String test) {
        this.test = test;
    }   
}
Bohemian
  • 412,405
  • 93
  • 575
  • 722
c12
  • 9,557
  • 48
  • 157
  • 253

1 Answers1

12

You need to add this header to your request:

Accept-Encoding:multipart/form-data

usually you use Content type like this:

Content-Type: image/png

You can test it with Postman REST client

I've attached an image on how the form should be filled out.

postman multipart/form-data

delkant
  • 2,304
  • 1
  • 29
  • 28