1

I am prototyping a very simple POST service to upload a file:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("fileUpload")
public Response uploadFile(MultipartBody body) {

    //never gets to here
    System.out.println("In uploadFile");

    //TODO: implementation

    return Response.ok().build();
}

I get

org.apache.cxf.interceptor.Fault: Couldn't determine the boundary from the message!

I also tried to replace the method declaration with:

public Response uploadFile(List<Attachment> attachments, 
    @Context HttpServletRequest request) {

as per some Google findings, to no help.

I am using two different clients to invoke this service: chrome://poster, which has a field to include a file attachment, and a simple Python script as is explained here. Both clients produce the same result.

How should I change my service implementation or the call or both in order to be able to pass the CXF validation and enter into the actual body of the service?

REFERENCES:

Community
  • 1
  • 1
amphibient
  • 29,770
  • 54
  • 146
  • 240

1 Answers1

3

The server side code looks fine. Problem is the way you are sending data from client. You are sending data as a stream in payload not as an attachment which has boundary. To verify quickly you can enable logging request and response by enabling CXF Feature LoggingFeature or Interceptors LoggingInInterceptor and LoggingoutInterceptor. In the log if you see data coming Payload then you are sending data as stream in this case you need to change the way you send the data else you can change consumes to application/octetstream and receive data using inputstream directly.


I'm not aware of the tool you are using, however I use Chrome Extension to postman to test the REST services. If you install the extension and launch the application.

You can upload the file using below approach.

enter image description here

  1. Change Method type to POST from the drop down.
  2. Enter the URL
  3. Select Tab Body
  4. Select Form-Data Radio Button
  5. On the right most row select file from drop down. as shown in diagram.
  6. Choose file to upload.
  7. Optional enter multipart key.
  8. Finally click send.

We can reproduce your error by selecting binary radio button and uploading file as shown below.

enter image description here

Karthik Prasad
  • 9,662
  • 10
  • 64
  • 112