multi file upload with play?

我的梦境 提交于 2019-11-30 15:25:41

I've found a hackish way.

You have to import play.data.Upload or play.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 the File fake argument the method will not handle multipart/form-data and you'll get an empty request.args array. If anyone knows the play/standard annotation for it, let me know :)

You can check this for other useful functions - http://www.playframework.org/documentation/api/1.2.3/play/data/FileUpload.html

Hope it'll solve your problem.

I had the same problem but with an input field for multiple itens.

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

The problem was solved using an array instead of a List, in the action parameters:

public static void overviewSubmit(File[] files){
    System.out.println(files);
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!