146°

dropzone上传多文件,java后台接受不到文件数据

1--修改js源码(后台使用的是MultipartFile[]数组接收)
源码 中搜搜uploadMultiple,将
 return "" + this.options.paramName + (this.options.uploadMultiple ? "[" + n + "]" : "");
修改为:
return "" + this.options.paramName + (this.options.uploadMultiple ? "" : "");
2--后台修改接受方法---不使用MultipartFile[]数组接收,直接通过MultipartHttpServletRequest获取参数。
@RequestMapping(value="/upload")
@ResponseBody
public Object uploadExcel(@ApiParam(required = true, name = "month", value = "上传月份") @RequestParam(value = "month") String month,
                         // @ApiParam(required = true, name = "file", value = "文件流")@RequestParam(value = "file", required = false) MultipartFile[] files,
                          HttpServletRequest request, HttpServletResponse response){
    HashMap<String, Object> map = new HashMap<>();
    StringBuffer sb = new StringBuffer();
    //判断是否有文件
    MultipartHttpServletRequest request1 = (MultipartHttpServletRequest)request;
    MultiValueMap<String, MultipartFile> multiFileMap = request1.getMultiFileMap();
    Collection<List<MultipartFile>> values = multiFileMap.values();
    if(values.size()>0){
        for (List<MultipartFile> files:values
                ) {
            try{
                for (MultipartFile file:files
                        ) {
                    Map<String,Object> res = excelImportSingle(file, month);
                    if(!(Boolean)res.get("success")){//文件上传失败
                        sb.append(res.get("msg")+"$");
                    }else {
                        sb.append(res.get("msg")+"$");
                    }
                }
                map.put("success",true);
                map.put("msg",sb.toString());
            }catch (Exception e){
                map.put("success",false);
                map.put("msg","文件上传异常,请选择单个上传!");
            }
        }
    }else {
        map.put("success",false);
        map.put("msg","上传文件为空!");
    }
    return map;
}

 

本文由【Sheav】发布于开源中国,原文链接:https://my.oschina.net/shea1992/blog/2240063

全部评论: 0

    我有话说: