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

Allow injection of @FormParam InputPart fields in @MultipartForm parameters

    Details

      Description

      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" .

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  asoldano Alessio Soldano
                  Reporter:
                  chrisjr Chris Rankin
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: