multi file upload with play?

后端 未结 2 1568
天涯浪人
天涯浪人 2021-01-03 06:56

I try to upload multiple files with one request. My code looks like the following:

相关标签:
2条回答
  • 2021-01-03 07:13

    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.

    0 讨论(0)
  • 2021-01-03 07:23

    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);
    } 
    
    0 讨论(0)
提交回复
热议问题