单个文件
@ApiOperation(value = "上传视频接口",notes = "上传视频接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "uId",value = "上传用户ID,",paramType = "query",required = true,dataType = "int")
})
@PostMapping(value = "/video/uplode", headers = "content-type=multipart/form-data")
public ResponseJsonCode uplode(HttpServletRequest request,@RequestParam(value = "uId", required = true) String uId, @RequestParam(value = "file", required = true) MultipartFile file) {
Map<String,Object> dataMap = new HashMap<String,Object>();
String path="";
log.info("file:"+file.length+"; uId:"+uId+"; path:"+path);
List<Map<String,Object>> list = IOUtil.appMvcUpload(path, file, request,dataMap);
return null==list.get(0).get("error")?ResponseJsonCode.successRequestJsonCode(list):ResponseJsonCode.errorRequestJsonCode(list);
}
多文件(用postman测试)
@ApiOperation(value = "文件上传",notes = "文件上传")
@ApiImplicitParams({
@ApiImplicitParam(name = "files",value = "多个文件,",paramType = "formData",allowMultiple=true,required = true,dataType = "file"),
@ApiImplicitParam(name = "uId",value = "上传用户ID,",paramType = "query",required = true,dataType = "int")
})
@PostMapping(value = "/uplode", headers = "content-type=multipart/form-data")
public ResponseJsonCode uplode(HttpServletRequest request,@RequestParam(value = "uId", required = true) String uId, @RequestParam(value = "files", required = true) MultipartFile[] files) {
Map<String,Object> dataMap = new HashMap<String,Object>();
String path="";
log.info("files:"+files.length+";uId:"+uId+": path:"+path);
List<Map<String,Object>> list = IOUtil.appMvcUpload(path, files, request,dataMap);
return null==list.get(0).get("error")?ResponseJsonCode.successRequestJsonCode(list):ResponseJsonCode.errorRequestJsonCode(list);
}
参考链接:https://blog.csdn.net/persistencegoing/article/details/87892640