Multi-file download with the game?

I am trying to upload multiple files in one request. My code is as follows:

<form action="/application/overviewsubmit" method="POST" enctype="multipart/form-data">
 <input type="file" name="files">
 <input type="file" name="files">
 <input type="submit" value="Run...">
</form>

And the controller:

public static void overviewSubmit(List<File> files){
 System.out.println(files);
}

If both files are installed by the user, it works. But if the user selects only one of them and leaves the other untouched, the files are always zero.

+4
source share
2 answers

I found a hacker way.

You need to import play.data.Uploadorplay.data.*

public static void overviewsubmit(File fake) {
    List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");
    for(Upload file: files) {
        Logger.info("Size = %d", file.getSize());
    }
}

Without an argument, the File fakemethod will not process multipart/form-data, and you will get an empty array request.args. If someone knows the standard annotation for the game, let me know :)

- http://www.playframework.org/documentation/api/1.2.3/play/data/FileUpload.html

, .

+7

, itens.

<input type="file" multiple="multiple" name="file" >

:

public static void overviewSubmit(File[] files){
    System.out.println(files);
} 
0

All Articles