0

I need to build a service that can receive 2 binary files (~100k each) and some metadata, preferably in json.

I found this, but it only seems to provide one InputStream to one of the parts. But I'd need two.. so what to do?

Community
  • 1
  • 1
Bobby
  • 1,666
  • 3
  • 16
  • 27

1 Answers1

1

You have a few options

  1. Simply add another parameter(s) with a different part annotation

    @POST
    @Consumes("multipart/form-data")
    public Response post(@FormDataParam("file1") InputStream file1,
                         @FormDaraParam("file2") InputStream file2) {
    
    }
    
  2. The parts can have the same part name, so you could do

    @POST
    @Consumes("multipart/form-data")
    public Response post(@FormDataParam("file") List<FormDataBodyPart> files) {
        for (FormDataBodyPart file: files) {
            FormDataContentDisposition fdcd = file.getFormDataContentDisposition();
            String fileName = fdcd = getFileName();
            InputStream is = file.getValueAs(InputStream.class);
        }
    }
    
  3. You could traverse the entire multipart body youself

    @POST
    @Consumes("multipart/form-data")
    public Response post(FormDataMultiPart mulitPart) {
        Map<String, List<FormDataBodyPart>> fields = multiPart.getFields();
    }
    

See Also:

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720