Posting data with multiple data to the seam + RESTeasy does not allow sorting InputStream

I try to send image data to the end of the seam + RESTeasy, and when I start JBoss I get a very cryptic error. The HTTP request that I am sending has the content type multipart / form-data, which has one image / jpeg part called attachment. My maintenance method is as follows:

@POST
@Path("uploadSymptomsImage/{appointmentGUID}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public String uploadSymptomsImage( @FormParam("attachment") InputStream fileInputStream,
                                   @PathParam("appointmentGUID") String strAppointmentGUID )
{ ...

The error I get at startup:

Caused by: java.lang.RuntimeException: Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.FormParam("attachment") on public java.lang.String com....AppointmentRestService.uploadSymptomsImage(java.io.InputStream,java.lang.String) for basetype: java.io.InputStream
at org.jboss.resteasy.core.StringParameterInjector.initialize(StringParameterInjector.java:206) [:]
at org.jboss.resteasy.core.StringParameterInjector.<init>(StringParameterInjector.java:57) [:]
at org.jboss.resteasy.core.FormParamInjector.<init>(FormParamInjector.java:22) [:]

My understanding was that media types can be automatically sorted into an InputStream. I also tried java.io.File, java.io.Reader - with the same error. When I replace with [] or String byte, I get an array of zero length or null as the parameter value.

? , ?

.

+5
1

, MultipartFormDataInput. . :

@POST
@Path("uploadSymptomsImage/{appointmentGUID}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public String uploadSymptomsImage(@PathParam("appointmentGUID") String strAppointmentGUID,
                               MultipartFormDataInput formData) {

    Map<String, List<InputPart>> formDataMap = formData.getFormDataMap();

   List<InputPart> attachments = formDataMap.get("attachment");
   for(InputPart attachment : attachments) {
        String fileName = extractFilename(attachment);
        if(fileName.isEmpty()) continue;
        InputStream in = attachment.getBody(new GenericType<InputStream>() {});
        // Interact with stream
   }

    // Respond
}

extractFilename :

private static String extractFilename(final InputPart attachment) {
    Preconditions.checkNotNull(attachment);
    MultivaluedMap<String, String> headers = attachment.getHeaders();
    String contentDispositionHeader = headers.getFirst("Content-Disposition");
    Preconditions.checkNotNull(contentDispositionHeader);

    for(String headerPart : contentDispositionHeader.split(";(\\s)+")) {
        String[] split = headerPart.split("=");
        if(split.length == 2 && split[0].equalsIgnoreCase("filename")) {
            return split[1].replace("\"", "");
        }
    }

    return null;
}
0

All Articles