Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1405

Allow injection of @FormParam InputPart fields in @MultipartForm parameters

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Minor Minor
    • 3.1.0.Beta2, 3.0.20.Final
    • 3.0.17.Final
    • jaxrs
    • None

      I have been trying to read the Content-Type for an InputStream field belonging to a @MultipartForm parameter. This particular parameter also needs to integrate with Hibernate Validator:

      @Consumes("multipart/form-data")
      @POST
      Response myApi(
          @Valid
          @NotNull
          @MultipartForm
          MyRequest request
      );
      

      where

      public class MyRequest {
      
          @FormParam("header")
          @NotNull(message = "{ etc etc }")
          @Valid
          private MyHeader header;
      
          @FormParam("stuff")
          @NotNull(message = "{ etc etc }")
          private InputStream stuff;
      
      }
      

      However, any attempt to access the InputPart associated with form parameter "stuff" closes the InputStream. So I suggest updating MultipartFormAnnotationReader so that it supports InputPart as well as InputStream, e.g.

      public class MyRequest {
      
          @FormParam("header")
          @NotNull(message = "{ etc etc }")
          @Valid
          private MyHeader header;
      
          @FormParam("stuff")
          @NotNull(message = "{ etc etc }")
          private InputPart stuff;
      
      }
      

      I can then retrieve the InputStream using getBody(InputStream.class, null) and also get the field's associated Content-Type header "for free" .

              rhn-support-asoldano Alessio Soldano
              chrisjr_jira Chris Rankin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: