playframework Server端接受POST multipart/form-data请求

来源:互联网 发布:系统重装的软件 编辑:程序博客网 时间:2024/05/29 16:35

playframework Server端接受POST multipart/form-data请求,接收Client端发送的多个文件

static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");    public static void getUploadFile(String file) {         String dataDirName=simpleDateFormat.format(new Date());        String path="/home/Accept/"+dataDirName+"/";        File toSave = new File(path);        if (!toSave.exists()) {            toSave.mkdirs();        }        JSONObject result = new JSONObject();        try {            List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");            for (Upload upload : files) {                if (upload.getSize() > 0) {                    File f = upload.asFile();                    String fileName = f.getName();                    File storeFile = new File(path+ fileName);                    Logger.info("####"+path+fileName);                    Files.copy(f, storeFile);                }            }        } catch (Exception e) {            result.put("flag", false);            result.put("msg", "操作失败");        }        result.put("flag", true);        result.put("msg", "操作成功");        renderJSON(result);    } 
原创粉丝点击