Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Use a parameter as FileItem[] file in Controller #571

Open
decebals opened this issue Nov 20, 2020 · 1 comment
Open

[Question] Use a parameter as FileItem[] file in Controller #571

decebals opened this issue Nov 20, 2020 · 1 comment
Labels

Comments

@decebals
Copy link
Member

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
Copy link
Member Author

decebals commented Nov 20, 2020

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant