snowdrop-zen / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
1 stars 0 forks source link

Multipart file upload, bind files with same field name to the specified field #338

Closed snowdrop-bot closed 3 years ago

snowdrop-bot commented 3 years ago

Description

Currently in master this commit added support for capturing multiple file uploads into a list with the caveat that the @RestForm value should not be set. In my opinion we should implement instead the possibility to set a name to group file uploads into two different fields.

Implementation ideas

For example if I have a form pojo like this:

class Form {

   @RestForm
   List<FileUpload> attachments;
}

Then the default behavior that is already implemented would execute and caputre all file uploads into this field. If, instead, I have two fields like this:

class Form {

   @RestForm("images")
   List<FileUpload> images;

   @RestForm("attachments")
   List<FileUpload> attachments;
}

The backen would caputer into images the file uploads coming from the form field images which can be duplicated. Example request:

POST /send/email HTTP/1.1
Host: localhost:8091
Accept: application/stream+json
Content-Length: 595
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="payload"
Content-Type: application/json

{
  "test": "test"
}
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="images"; filename="pic1.jpg"
Content-Type: image/jpeg

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="images"; filename="pic2.jpg"
Content-Type: image/jpeg

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="attachments"; filename="pic1.jpg"
Content-Type: image/jpeg

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW

https://github.com/quarkusio/quarkus/issues/17246


$upstream:17246$