pippo icon indicating copy to clipboard operation
pippo copied to clipboard

[Question] Use a parameter as `FileItem[] file` in Controller

Open decebals opened this issue 5 years ago • 1 comments

In my TestCntroller.java I have a web method like:

@POST("/test")
public void test(@Param FileItem[] files) {
    return getResonse().ok().text("Test");
}

In HTML template I have something like:

<form action="/test" method="post" enctype="multipart/form-data">
    <input type="file" name="files" class="filestyle" multiple>
    // submit button
<form>

Is someone use a such approach approach in their Pippo's based application?

Or List<FileItem> files instead of FileItems[] files.

decebals avatar Nov 20 '20 16:11 decebals

To not forget, I have a remark related to this subject. When I select multiple files, in server (by the way, I use Jetty in this project), I have multiple parts with the same name (files): image

If you take a look at HttpServletRequest (Servlet API) you will see that they are two methods related to parts:

  • getPart(String name): Part
  • getParts(): Collection<Part>

So, here we have a problem (in Servlet API) because they are multiple parts with the same name (files in my case), and getPart(name) returns only one Part (probably is the first).

decebals avatar Nov 20 '20 16:11 decebals